Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing First line in existing Flat file 2

Status
Not open for further replies.

longs

Programmer
Jul 27, 2007
31
US
HI all

Can any one please help me with this? I have a flat file. I just want to add something to its first line and not want to touch rest of the file. e.g


Firstlineofflatfile20080220
010800650022000003190000000+000002ECLPSE BIG E SPEAR000022505 ^M
010800650034000003470000000+000006YORK MINT TIN 000012405 ^M
010800650012546310530000000+000003DENTYNE ICE GUM 000022005 ^M
010800650012546310510000000+000001DENTYNE ICE GUM 000022005 ^M
010800650034000003470000000+000006YORK MINT TIN 000012405 ^M
010800650022000004660000000+000009ALTD CHC DP MNTS 000018005 ^M
010800650022000004670000000+000012ALTOID DK CHC CINN000018005 ^M
010800650022000159330000000+000008ALTOIDS MINTS DP 1000012205 ^M

after script is done i want my file to look like:

Firstlineofflatfile20080220ADDEDTEXTHERE
010800650022000003190000000+000002ECLPSE BIG E SPEAR000022505 ^M
010800650034000003470000000+000006YORK MINT TIN 000012405 ^M
010800650012546310530000000+000003DENTYNE ICE GUM 000022005 ^M
010800650012546310510000000+000001DENTYNE ICE GUM 000022005 ^M
010800650034000003470000000+000006YORK MINT TIN 000012405 ^M
010800650022000004660000000+000009ALTD CHC DP MNTS 000018005 ^M
010800650022000004670000000+000012ALTOID DK CHC CINN000018005 ^M
010800650022000159330000000+000008ALTOIDS MINTS DP 1000012205 ^M

Thanks
 
Something like this...
Code:
sed '1s/$/ADDEDTEXTHERE/1' inputfile.txt > outputfile.txt
 
Hi all if I want to use vaiable?
im try to do this but im can't get pass it

file_name=data_file20080214

sed '1s/$/$file_name/1' $txt_file > new_data_file

when I used this i got
Firstlineofflatfile20080220$file_name

how can i get;
Firstlineofflatfile20080220data_file20080214

Thanks
for all your help guys
 
Code:
sed '1s/$/'"$file_name/1" $txt_file > new_data_file

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Or...
Code:
sed "1s/\$/$file_name/1" inputfile.txt > outputfile.txt
It wasn't translating the variable because it was in single quotes ' '. The shell won't translate anything in single quotes, so you have to get the variable into double quotes some how " ". The shell will translate variables in double quotes.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top