Add string end of line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add string end of line
# 8  
Old 05-19-2010
Quote:
Originally Posted by ldiaz2106
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.
Sorry, try this:
Code:
awk '$2==100{$0=$0 "$$cData"}1' file

# 9  
Old 05-19-2010
Code:
awk '{print $0 (($2==100)? "$$cData":"")}' file

# 10  
Old 05-19-2010
Yes this code is the correct...
awk '{print $0 (($2==100)? "$$cData":"")}' file


If you have time Smilie could you please explain this code??
It's magic for me !!
Thanks

---------- Post updated at 02:42 PM ---------- Previous update was at 02:38 PM ----------

Hi Again

I have an other problem with my file, it's the same idea I think...
Look this fragment of file:

Code:
000000001 653   L $$aFORTRAN
000000001 653   L $$aSTRAIGHT-LINE PATH APPROXIMATION
000000001 700   L $$aROMERO, L.$$cCIEMAT
000000001 700   L $$aTRAVESI, A.
000000001 710   L $$aJUNTA DE ENERGIA NUCLEAR

As you can see, there is a $$cCIEMAT information in the line with first field 700.
Is it possible to detect all the $$cCIEMAT string in all the line whitch contains the fied 700 and remove the line?

So the result will be:

Code:
000000001 653   L $$aFORTRAN
000000001 653   L $$aSTRAIGHT-LINE PATH APPROXIMATION
000000001 700   L $$aTRAVESI, A.
000000001 710   L $$aJUNTA DE ENERGIA NUCLEAR

Do'nt forget that in my file I have 34000 records the first field is the ID
So the second record is:

Code:
000000002 653   L $$aFORTRAN
 000000002 653   L $$aSTRAIGHT-LINE PATH APPROXIMATION
 000000002 700   L $$aTRAVESI, A.
 000000002 710   L $$aJUNTA DE ENERGIA NUCLEAR

etc...

Thanks
# 11  
Old 05-19-2010
Code:
awk '$2 != "700" && $NF !~ "[$$]cCIEMAT" {print $0 (($2==100)? "$$cData":"")}' file

# 12  
Old 05-19-2010
Hi

whaaa all the lines with 700 have disapear.ejeje I need to remove only those with $$cCIEMAT at the end..

Exemple:

Code:
000000001 653   L $$aFORTRAN
000000001 653   L $$aSTRAIGHT-LINE PATH APPROXIMATION
000000001 700   L $$aROMERO, L.$$cCIEMAT
000000001 700   L $$aTRAVESI, A.
000000001 710   L $$aJUNTA DE ENERGIA NUCLEAR
000000001 710   L $$aJEN
000000001 852   L $$aCENTRO DE

only remove the line with 700 as field code, and $$cCIEMAT at the end, the other AUTHOR must stay...Thanks and sorry not explain correctly

Cheers
# 13  
Old 05-19-2010
Sorry...
Code:
awk '$2 == "700" && $NF ~ "[$$]cCIEMAT"{next} {print $0 (($2==100)? "$$cData":"")}' file

# 14  
Old 05-19-2010
Hi

great !!! this time is ok and I see that we done all the tasks in one shoot...
Sed and awk !!! I love it.
Thanks again
Have a nice evening !!

Cheers
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