Skip to main content
added 49 characters in body
Source Link
Archemar
  • 32.3k
  • 18
  • 75
  • 107

try

 ... | awk '$1 == "1" {print $2 ; l=NR+1 ; } NR == l { print $1 ;}'

where

  • $1 == "1" select line where first field is 1
  • {print $2 print it's value
  • l=NR+1 ; } remember next line
  • NR == l select second line
  • { print $1 ;} print first field

remember awk doesn't think in term of column, just field.

thoses two lines are equivalent using $1 $2

 hello world
       hello              world

Assigning to var

... | awk '$1 == "1" {printf "A=%s\n" ,$2 ; l=NR+1 ; } NR == l { printf "B=%s\n" ,$1 ;}' > /tmp/.var
. /tmp/.var

last line is a dot (.) a space ( ) and /tmp/.var

  • printf in awk need a comma after argument.

try

 ... | awk '$1 == "1" {print $2 ; l=NR+1 ; } NR == l { print $1 ;}'

where

  • $1 == "1" select line where first field is 1
  • {print $2 print it's value
  • l=NR+1 ; } remember next line
  • NR == l select second line
  • { print $1 ;} print first field

remember awk doesn't think in term of column, just field.

thoses two lines are equivalent using $1 $2

 hello world
       hello              world

Assigning to var

... | awk '$1 == "1" {printf "A=%s\n" $2 ; l=NR+1 ; } NR == l { printf "B=%s\n" $1 ;}' > /tmp/.var
. /tmp/.var

last line is a dot (.) a space ( ) and /tmp/.var

try

 ... | awk '$1 == "1" {print $2 ; l=NR+1 ; } NR == l { print $1 ;}'

where

  • $1 == "1" select line where first field is 1
  • {print $2 print it's value
  • l=NR+1 ; } remember next line
  • NR == l select second line
  • { print $1 ;} print first field

remember awk doesn't think in term of column, just field.

thoses two lines are equivalent using $1 $2

 hello world
       hello              world

Assigning to var

... | awk '$1 == "1" {printf "A=%s\n",$2 ; l=NR+1 ; } NR == l { printf "B=%s\n",$1 ;}' > /tmp/.var
. /tmp/.var

last line is a dot (.) a space ( ) and /tmp/.var

  • printf in awk need a comma after argument.
added 58 characters in body
Source Link
Archemar
  • 32.3k
  • 18
  • 75
  • 107

try

 ... | awk '$1 == "1" {print $2 ; l=NR+1 ; } NR == l { print $1 ;}'

where

  • $1 == "1" select line where first field is 1
  • {print $2 print it's value
  • l=NR+1 ; } remember next line
  • NR == l select second line
  • { print $1 ;} print first field

remember awk doesn't think in term of column, just field.

thoses two lines are equivalent using $1 $2

 hello world
       hello              world

Assigning to var

... | awk '$1 == "1" {printf "A=%s\n" $2 ; l=NR+1 ; } NR == l { printf "B=%s\n" $1 ;}' > /tmp/.var
. /tmp/.var

last line is a dot (.) a space ( ) and /tmp/.var

try

 ... | awk '$1 == "1" {print $2 ; l=NR+1 ; } NR == l { print $1 ;}'

where

  • $1 == "1" select line where first field is 1
  • {print $2 print it's value
  • l=NR+1 ; } remember next line
  • NR == l select second line
  • { print $1 ;} print first field

remember awk doesn't think in term of column, just field.

thoses two lines are equivalent using $1 $2

 hello world
       hello              world

Assigning to var

... | awk '$1 == "1" {printf "A=%s\n" $2 ; l=NR+1 ; } NR == l { printf "B=%s\n" $1 ;}' > /tmp/.var
. /tmp/.var

try

 ... | awk '$1 == "1" {print $2 ; l=NR+1 ; } NR == l { print $1 ;}'

where

  • $1 == "1" select line where first field is 1
  • {print $2 print it's value
  • l=NR+1 ; } remember next line
  • NR == l select second line
  • { print $1 ;} print first field

remember awk doesn't think in term of column, just field.

thoses two lines are equivalent using $1 $2

 hello world
       hello              world

Assigning to var

... | awk '$1 == "1" {printf "A=%s\n" $2 ; l=NR+1 ; } NR == l { printf "B=%s\n" $1 ;}' > /tmp/.var
. /tmp/.var

last line is a dot (.) a space ( ) and /tmp/.var

added 149 characters in body
Source Link
Archemar
  • 32.3k
  • 18
  • 75
  • 107

try

 ... | awk '$1 == "1" {print $2 ; l=NR+1 ; } NR == l { print $1 ;}'

where

  • $1 == "1" select line where first field is 1
  • {print $2 print it's value
  • l=NR+1 ; } remember next line
  • NR == l select second line
  • { print $1 ;} print first field

remember awk doesn't think in term of column, just field.

thoses two lines are equivalent using $1 $2

 hello world
       hello              world

Assigning to var

... | awk '$1 == "1" {printf "A=%s\n" $2 ; l=NR+1 ; } NR == l { printf "B=%s\n" $1 ;}' > /tmp/.var
. /tmp/.var

try

 ... | awk '$1 == "1" {print $2 ; l=NR+1 ; } NR == l { print $1 ;}'

where

  • $1 == "1" select line where first field is 1
  • {print $2 print it's value
  • l=NR+1 ; } remember next line
  • NR == l select second line
  • { print $1 ;} print first field

remember awk doesn't think in term of column, just field.

thoses two lines are equivalent using $1 $2

 hello world
       hello              world

try

 ... | awk '$1 == "1" {print $2 ; l=NR+1 ; } NR == l { print $1 ;}'

where

  • $1 == "1" select line where first field is 1
  • {print $2 print it's value
  • l=NR+1 ; } remember next line
  • NR == l select second line
  • { print $1 ;} print first field

remember awk doesn't think in term of column, just field.

thoses two lines are equivalent using $1 $2

 hello world
       hello              world

Assigning to var

... | awk '$1 == "1" {printf "A=%s\n" $2 ; l=NR+1 ; } NR == l { printf "B=%s\n" $1 ;}' > /tmp/.var
. /tmp/.var
Source Link
Archemar
  • 32.3k
  • 18
  • 75
  • 107
Loading