Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Trouble using awk command

$
0
0
Hi,

I have 2 .txt pads containing data.
I need a script which reads content of one .txt file, performs some operations and calculates a number which is stored in a variable.
Now , all the content of another .txt pad should be appended to first .txt pad at pre calculated nth line number.

Below is sample data and commands i tried
Code:

> cat temp.dml
record
  decimal("\x01") lst_updt_run_id; /* INTEGER NOT NULL*/
decimal("\x01") invalid_data;
end;
 
cat > t.txt
this is the first line
[[this is second line]]
. h.ksh
 
expected O/P: If want to append at 1st line
 
this is the first line
[[this is second line]]
. h.ksh
record
  decimal("\x01") lst_updt_run_id; /* INTEGER NOT NULL*/
decimal("\x01") invalid_data;
end;
 
tried code:
> awk 'NR==1{file="t.txt";while ((getline<file) > 0) {print}}1' temp.dml | uniq
this is the first line
[[this is second line]]
. h.ksh
  decimal("\x01") lst_updt_run_id; /* INTEGER NOT NULL*/
decimal("\x01") invalid_data;
end;

there were couple of issues faced:
1. I tried matching NR with a variable which contains the line position to append but it was not working.
2.Last row of second .txt pad is repeating and hence i used uniq keyword.

Any solutions to this?

Viewing all articles
Browse latest Browse all 16232

Trending Articles