Visit Our UNIX and Linux User Community


Concatenate strings retrieved from a file and write it into another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Concatenate strings retrieved from a file and write it into another file
# 1  
Old 07-22-2011
Concatenate strings retrieved from a file and write it into another file

Hi,

I have a file files.txt containing data as below:
Code:
abc;xyz
uvw;pqr
123;456

I want to develop strings like below using the above data and write them into another file:
Code:
www/xxx/abc/yyy/xyz
www/xxx/uvw/yyy/pqr
www/xxx/123/yyy/456

All this needs to be done through .sh file.

Could you please help?

Last edited by Franklin52; 07-22-2011 at 07:01 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 07-22-2011
Code:
 
nawk -F";" '{printf("www/xxx/%s/yyy/%s\n",$1,$2)}' files.txt

# 3  
Old 07-22-2011
Code:
sed 's/\(.*\);\(.*\)/\www\/xxx\/\1\/yyy\/\2/'  <File_Name>


Last edited by Franklin52; 07-22-2011 at 07:01 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 07-22-2011
Quote:
Originally Posted by itkamaraj
Code:
 
nawk -F";" '{printf("www/xxx/%s/yyy/%s\n",$1,$2)}' files.txt

just same as this..

Code:
awk -F";" '{print "www/xxx/"$1"/yyy/"$2}' inputfile

# 5  
Old 07-22-2011
Alternate Sed..
Code:
sed 's|^|www/xxx/|;s|;|/yyy/|' inputfile > outfile


Previous Thread | Next Thread
Test Your Knowledge in Computers #398
Difficulty: Medium
HP-UX offers operating system-level virtualization features such as hardware partitions, isolated OS virtual partitions on cell-based servers, and HP Integrity Virtual Machines (HPVM) on all Integrity servers.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies

2. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

3. Shell Programming and Scripting

Search for string in a file, extract two another strings and concatenate to a variable

I have a file with <suit:run date="Trump Tue 06/19/2012 11:41 AM EDT" machine="garg-ln" build="19921" level="beta" release="6.1.5" os="Linux"> Need to find word "build" then extract build number, which is 19921 also release number, which is 6.1.5 then concatenate them to one variable as... (6 Replies)
Discussion started by: garg
6 Replies

4. Web Development

Concatenate Strings

hi..:) this is my sample part of my program.. $csv_output .= $row.",". $row.",". $row.",". $row.",". $row.",". ... (2 Replies)
Discussion started by: Jeneca
2 Replies

5. UNIX for Dummies Questions & Answers

concatenate strings

if i use echo "ravi" echo "sankar" it showing output ravi sankar but i want output as ravi sankar remember sankar should be in another echo statement only (2 Replies)
Discussion started by: shankr3
2 Replies

6. Shell Programming and Scripting

How to write a script to extract strings from a file.

Hello fourm members, I want to write a script to extarct paticular strings from the all type of files(.sh files,logfiles,txtfiles) and redirect into a log file. example: I have to find the line below in the script and extract the uname and Pwds. sqsh -scia2007 -DD0011uw01 -uciadev... (5 Replies)
Discussion started by: rajkumar_g
5 Replies

7. Shell Programming and Scripting

Execute command on first column (filename) retrieved from a file

Hi, I have a file abcd.txt which in turn contains 20 file names as column 1. Now I want to run a command "ct co -nc" / "cp" / "mv" on each of these $1 column content i.e. on each of the 20 file names. How can do this using a script so that I need not run the same command 20 times... (13 Replies)
Discussion started by: royzlife
13 Replies

8. UNIX for Dummies Questions & Answers

Concatenate Strings

Hi Friends, I have a requirement I need to concatenate the below two strings. String 1 = /@jobid_at_ String 2 = value stored in ORACLE_SID String 3 = string1 concatenated with String 2. Please let me know how should i do it in UNIX. Thanks, (2 Replies)
Discussion started by: diva_thilak
2 Replies

9. Shell Programming and Scripting

How to concatenate two strings or several strings into one string in B-shell?

like connect "summer" and "winter" to "summerwinter"? Can anybody help me? thanks a lot. (2 Replies)
Discussion started by: fontana
2 Replies

Featured Tech Videos