The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk, join or sed jkl_jkl Shell Programming and Scripting 1 04-15-2008 02:55 AM
Join jazz8146 UNIX for Dummies Questions & Answers 5 01-29-2008 07:42 AM
join (pls help on join command) summer_cherry Shell Programming and Scripting 1 12-31-2007 01:19 AM
How to concatenate two strings or several strings into one string in B-shell? fontana Shell Programming and Scripting 2 08-26-2005 08:58 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-22-2008
Registered User
 

Join Date: Apr 2008
Posts: 16
Stumble this Post!
Question How to join two strings together

There is a file:

!EN
ih
n
w
ey


I want to join the current instance with its previous instance together, such as: previous_instance-B+current_instance, there "-B+" is fixed iterm, the file after operate look like:

!EN start-B+!EN
ih !EN-B+ih
n ih-B+n
w n-B+w
ey w-B+ey

what I think is we can use command
awk ' {being="start";$2=${begin}-B+$1;print;begin=$1;next}' <filename > newfilename

but it does not work.

what command should I use? Thanks in advance

Last edited by Jenny.palmy; 05-22-2008 at 08:07 PM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-22-2008
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,243
Stumble this Post!
Try...
Code:
$ cat file1
!EN
ih
n
w
ey

$ awk 'BEGIN{b="start"}{$2=b "-B+" $1;print;b=$1}' file1 > file2

$ cat file2
!EN start-B+!EN
ih !EN-B+ih
n ih-B+n
w n-B+w
ey w-B+ey
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0