Add string end of line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add string end of line
# 1  
Old 05-19-2010
Add string end of line

Hello
How can I add a string (always the same) at the end of a specific line in a file...
The file is:

Code:
000000001 041   L $$aspa
000000001 088   L $$aJ.E.N. 551
000000001 090   L $$aINFORMES JEN
000000001 100   L $$aautor 1
----
000000002 041   L $$aeng
000000002 088   L $$aJ.E.N. 1
000000002 090   L $$aINFORMES
000000002 100   L $$aautor2

Then I would like to add this $$cData at the end of the autor line for each records
Like this:

Code:
000000002 100   L $$aautor2$$cData

I try with sed:

Code:
sed -i '/$[0-9]\{9\} 100/$$cData/' luis.dat

But I have an error
Code:
sed: -e expression #1, char 18: unknown command: `$'

Thanks to help
# 2  
Old 05-19-2010
Code:
sed 's/[$$]aautor.*/&$$cData/' luis.dat

# 3  
Old 05-19-2010
Nice
THanks a lot !!!!
sed is genial !
# 4  
Old 05-19-2010
Code:
#  sed '/aautor/s/\(.*\)/\1$$cData/' infile
000000001 041   L $$aspa
000000001 088   L $$aJ.E.N. 551
000000001 090   L $$aINFORMES JEN
000000001 100   L $$aautor 1$$cData
----
000000002 041   L $$aeng
000000002 088   L $$aJ.E.N. 1
000000002 090   L $$aINFORMES
000000002 100   L $$aautor2$$cData

or awk:

Code:
#  awk '/autor/{print $0"$$cData"}!/autor/{print}' infile 
000000001 041   L $$aspa
000000001 088   L $$aJ.E.N. 551
000000001 090   L $$aINFORMES JEN
000000001 100   L $$aautor 1$$cData
----
000000002 041   L $$aeng
000000002 088   L $$aJ.E.N. 1
000000002 090   L $$aINFORMES
000000002 100   L $$aautor2$$cData

HTH
# 5  
Old 05-19-2010
Hello
sorry for the confusion

the autor are not :aautor...but could be

Code:
000000001 100   L $$aPEPITO 1$$cData

000000001 100   L $$aLUIS 1$$cData
000000001 100   L $$aPEDRO 1$$cData

Etc... So in the sed command I must put what exactly?
This for example?
Code:
sed '/a*/s/\(.*\)/\1$$cData/' infile



---------- Post updated at 01:47 PM ---------- Previous update was at 01:44 PM ----------

Ha yes some ting important, only lines with field 100 have to be updated, no all the others.


So in this exemple:

Code:
000000001 088   L $$aJ.E.N. 551
000000001 090   L $$aINFORMES JEN
000000001 100   L $$aROMERO, L.

Only this line have to be changed like this:
Code:
000000001 100   L $$aROMERO, L.$$cData

Thanks

Last edited by Scott; 05-19-2010 at 03:48 PM.. Reason: Please use code tags
# 6  
Old 05-19-2010
Is this what you want?
Code:
awk '$2==100{print $0 "$$cData"}' file

# 7  
Old 05-19-2010
Hi
mmmm not exactly

look if I apply this command I have a file with this:

000000119 100 L $$aRUIZ SAENZ DE MIERA, A.$$cData
000000120 100 L $$aKIM, D.$$cData
000000121 100 L $$aMIKKELSEN, D.R.$$cData

So only field 100...But all the other fields have disapear.
Look a template of the original file:

Code:
000000001 LDR   L ^^^^^nam^^2200325Iia^45e0
000000001 022   L $$a0081-3397
000000001 041   L $$aspa
000000001 088   L $$aJ.E.N. 551
000000001 090   L $$aINFORMES JEN
000000001 100   L $$aROMERO, L.
000000001 245   L $$aCODIGO "REX" PARA AJUSTE DE DATOS EXPERIMENTALES A FUNCIONES EXPONENCIALES Y SU REPRESENTACION GRAFICA
000000001 250   L $$a1 ED
000000001 260   L $$aMADRID:$$b JUNTA DE ENERGIA NUCLEAR,$$c1983
000000001 300   L $$a58 P. + 5 REFERENCIAS BIBLIOGR., 1 H. DE FICHAS CON REFERENCIA BIBLIOGRAFICA Y RESUMEN DEL INFORME
000000001 340   L $$aPAPEL
....

That I want is this:

Code:
000000001 LDR   L ^^^^^nam^^2200325Iia^45e0
000000001 022   L $$a0081-3397
000000001 041   L $$aspa
000000001 088   L $$aJ.E.N. 551
000000001 090   L $$aINFORMES JEN
000000001 100   L $$aROMERO, L.$$cData
000000001 245   L $$aCODIGO "REX" PARA AJUSTE DE DATOS EXPERIMENTALES A FUNCIONES EXPONENCIALES Y SU REPRESENTACION GRAFICA
000000001 250   L $$a1 ED
000000001 260   L $$aMADRID:$$b JUNTA DE ENERGIA NUCLEAR,$$c1983
000000001 300   L $$a58 P. + 5 REFERENCIAS BIBLIOGR., 1 H. DE FICHAS CON REFERENCIA BIBLIOGRAFICA Y RESUMEN DEL INFORME
000000001 340   L $$aPAPEL

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

Suppress new line at end here string?

I'm trying to fully escape/quote a directory path for use in a regular expression with no characters interpreted symbolically. Printable characters get \* and white space gets "*" $ inputDirectory="/home/dir1/dir/" $ echo $( { while read -r -n1 a; do ] ]] && echo -n "\"""$a""\"" || echo -n... (7 Replies)
Discussion started by: Michael Stora
7 Replies

3. Red Hat

How to add a new string at the end of line by searching a string on the same line?

Hi, I have a file which is an extract of jil codes of all autosys jobs in our server. Sample jil code: ************************** permission:gx,wx date_conditions:yes days_of_week:all start_times:"05:00" condition: notrunning(appDev#box#ProductLoad)... (1 Reply)
Discussion started by: raghavendra
1 Replies

4. Shell Programming and Scripting

Add Date string at end of line

HOWTO Append Date String (MMYYYY) to End of Line file A.txt B.txt Output: A_052014.txt B_052014.txt (9 Replies)
Discussion started by: satish1222
9 Replies

5. Shell Programming and Scripting

Append this string to end of each line

Platform: Solaris 10 I have a file like below $ cat languages.txt Spanish Norwegian English Persian German Portugese Chinese Korean Hindi Malayalam Bengali Italian Greek Arabic I want to append the string " is a great language" at end of each line in this file. (3 Replies)
Discussion started by: omega3
3 Replies

6. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

7. Shell Programming and Scripting

put string end of the line

I've a problem to put .h end of the line..below my input file fg_a bb fg_b bb fg_c bb fg_d aa fg_f ee and i want the output file as below fg_a.h bb fg_b.h bb fg_c.h bb fg_d.h (6 Replies)
Discussion started by: zulabc
6 Replies

8. Shell Programming and Scripting

Get the 1st 99 characters and add new line feed at the end of the line

I have a file with varying record length in it. I need to reformat this file so that each line will have a length of 100 characters (99 characters + the line feed). AU * A01 EXPENSE 6990370000 CWF SUBC TRAVEL & MISC MY * A02 RESALE 6990788000 Y... (3 Replies)
Discussion started by: udelalv
3 Replies

9. Shell Programming and Scripting

Append a string at the end of every line in a file

Hi Friends, I have a file with many lines as shown below. /START SAMPLE LINE/ M:\mmarimut_v6.4.0_pit_01\java\build.xml@@\main\v6.4.0_pit_a M:\mmarimut_v6.4.0_pit_01\port\Post.java@@\main\v6.4.0_pit_a M:\mmarimut_v6.4.0_pit_01\switchview\View.java@@\main\v6.4.0_pit_a /END SAMPLE LINE/ I... (1 Reply)
Discussion started by: nmattam
1 Replies

10. Shell Programming and Scripting

To cut end string from line

HI, I want to cut end string from line. e.g. i have following input line /users/home/test.txt I want to get end string 'test.txt' from above line and length of that end string will change and it always start after '/'. Thanks, Visu (7 Replies)
Discussion started by: visu
7 Replies
Login or Register to Ask a Question