LiLi Liu
LiLi Liu

Reputation: 37

input file isn't being read correctly scripting awk

Hi I have two input files.

input1.txt:

id above
id below
id still
id getting

input2.txt

id above
value above the sky

id below
value under the chair

im trying to do an awk command and it shows up empty.

 awk -f find.awk input1.txt input2.txt

I know my awk works because im inputting 2 different txt files and all the outputs are correct and visible.

the difference between the different input2.txt files is...

when i go to use notepad on a windows machine the whole file turns out to be one string, while if you use any txt editor, it's formatted with separate lines.

example input2.txt on notepad.

  id above value above the sky id below value under the chair

I can't just reparse this input by id, because my real txt file has more data ... which is inconsistent so i can't just search for a string or reg expression.

find.awk

 FNR==NR  { id[$0]; next }  
 $0 in id { f=1 }           
 f                          
 NF==0    { f=0 }     

and idea on why my awk isn't working?

Upvotes: 0

Views: 148

Answers (1)

Ed Morton
Ed Morton

Reputation: 203169

Run "dos2unix" on your input files before running awk on them. man dos2unix.

Upvotes: 1

Related Questions