Append lines in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append lines in a file
# 1  
Old 08-17-2011
Append lines in a file

Legends,

Please help me out.

I have a file abc.txt with the following entries
Code:
JACK
JIL
SANDY
amer
europe
pak

Now, i want to append the character after each line.
but, condition is if it is UPPER case then character appended should be uppercase, else lowercase
example:
Code:
JACKL2
JILL2
SANDYL2
amerl2
europel2
pakl2

How do i do that ?

Please help

Moderator's Comments:
Mod Comment Please use code tags, thanks.

Last edited by zaxxon; 08-18-2011 at 02:32 AM.. Reason: code tags
# 2  
Old 08-17-2011
Code:
awk '{print /[[:upper:]]/?$0"L2":$0"l2"}' <yourfile>

# 3  
Old 08-17-2011
Quote:
Originally Posted by dude2cool
Code:
awk '{print /[[:upper:]]/?$0"L2":$0"l2"}' <yourfile>

But it's giving me following error

Code:
sandy>  awk '{print /[[:upper:]]/?$0"L2":$0"l2"}' /tmp/list
awk: syntax error near line 1
awk: illegal statement near line 1


Last edited by vbe; 08-17-2011 at 02:07 PM.. Reason: if you know how to use quotes you know how to use code
# 4  
Old 08-17-2011
Code:
$ awk ' { if($0~/[:upper:]/) {print $0"l2"}else{print $0"L2"} }' test
JACKL2
JILL2
SANDYL2
amerl2
europel2
pakl2

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 08-17-2011
Quote:
Originally Posted by itkamaraj
Code:
$ awk ' { if($0~/[:upper:]/) {print $0"l2"}else{print $0"L2"} }' test
JACKL2
JILL2
SANDYL2
amerl2
europel2
pakl2


THANK YOU itkamaraj
It works Smilie
# 6  
Old 08-18-2011
Through Sed..
Code:
sed 's/[[:upper:]]$/&L2/;s/[[:lower:]]$/&l2/' inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append next line to previous lines when NF is less than 0

Hi All, This is very urgent, I've a data file with 1.7 millions rows in the file and the delimiter is cedilla and I need to format the data in such a way that if the NF in the next row is less than 1, it will append that value to previous line. Any help will be appricated. Thanks,... (17 Replies)
Discussion started by: cumeh1624
17 Replies

2. Shell Programming and Scripting

Help with ksh-to read ip file & append lines to another file based on pattern match

Hi, I need help with this- input.txt : L B white X Y white A B brown M Y black Read this input file and if 3rd column is "white", then add specific lines to another file insert.txt. If 3rd column is brown, add different set of lines to insert.txt, and so on. For example, the given... (6 Replies)
Discussion started by: prashob123
6 Replies

3. Shell Programming and Scripting

Append lines from file 1 to file 2

File 1 : anupam testing testing123 File2: hello world last try Output file 3: anupamhello testingworld testing123last try it will be good in case we are not reading line one by one and appending...I tried like that only but it's taking time to execute.. So asking for bettr... (7 Replies)
Discussion started by: Anupam_Halder
7 Replies

4. UNIX for Dummies Questions & Answers

append following lines to 1st line, every 3 lines

I have output like this: USER_ID 12/31/69 19:00:00 12/31/69 19:00:00 USER_ID 12/31/69 19:00:00 12/31/69 19:00:00 USER_ID 12/31/69 19:00:00 12/31/69 19:00:00 USER_ID 12/31/69 19:00:00 12/31/69 19:00:00 ... where USER_ID is a unique user login followed by their login timestamp and... (6 Replies)
Discussion started by: MaindotC
6 Replies

5. Shell Programming and Scripting

how to append multiple lines to the last line of a file

Hello, This is what I am trying to achieve: file1 a b c d file2 e f g h (8 Replies)
Discussion started by: smarones
8 Replies

6. UNIX for Dummies Questions & Answers

Count Number Of lines in text files and append values to beginning of file

Hello, I have 50 text files in a directory called "AllFiles" I want to make a program that will go inside of the "AllFiles" Directory and count the number of lines in each individual text file. Then, the program will calculate how many more lines there are over 400 in each text file and... (7 Replies)
Discussion started by: motoxeryz125
7 Replies

7. Shell Programming and Scripting

Append lines in a file

Hi All, I have a file separated by , and each line end with ".If the line doesnt end with " then i need to join the current line and the next one and put them in another file a, b, c,d" d,f,g,h k, l m" o,p,q,r,t" ouput : a,b,c,d" d,f,g,h,k,l,m" o,p,q,r,t" (2 Replies)
Discussion started by: gwrm
2 Replies

8. Shell Programming and Scripting

Append variable to only certain lines

Hi There! I'm trying to write a shell script which generates a random hexadecimal number and then appends it to the end of lines XX onwards of a certain file. XX is determined by a certain string on the previous line. Thus for example, if the input file is I search for the string... (3 Replies)
Discussion started by: orno
3 Replies

9. Shell Programming and Scripting

Append lines with SED

I have the following data in a file and would like to append the lines inside each section 10, 20, 30, 40, etc... onto one line for each of the sections. Is it possible with SED to make this happen?? 10 00039393 DOCK: RECEIVE PART, TAG. D D ... (3 Replies)
Discussion started by: miklacic
3 Replies

10. UNIX for Dummies Questions & Answers

append word to lines

Hi all, Can someone suggest how to append some word to all lines in file. for example word "Honey" to file f1 with lines: Mia Katrin Elizabeth to get Honey Mia Honey Katrin Honey Elizabeth Thanks in advance Givi (3 Replies)
Discussion started by: giviut
3 Replies
Login or Register to Ask a Question