![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| Script to open program and send/execute command in program | tuathan | UNIX for Dummies Questions & Answers | 1 | 11-19-2008 09:59 PM |
| A program to trace execution of another program | jiten_hegde | High Level Programming | 3 | 08-19-2008 05:26 AM |
| How to write to stdin of another program (program A -> [stdin]program B) | vvaidyan | UNIX for Dummies Questions & Answers | 3 | 08-02-2008 05:21 PM |
| How to write to stdin of another program (program A -> [stdin]program B) | vvaidyan | High Level Programming | 1 | 04-30-2008 01:44 PM |
| executing a program within a program | Gekko | High Level Programming | 4 | 06-27-2002 03:36 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Hi all,
I need to grep the 3 characters from a file, and to fetch the corresponding words to that character. My file is in the following format.. The below text will be in the separate file....say file2.txt ABC This is the first text. DEF This is the second text. GH1 9.8.7890 AB1 This is the first1 text. DE2 This is the second1 text. GH2 19.8.7890 AB3 This is the first2 text. DE3 This is the second2 text. GH3 29.5.7890 AB4 This is the first3 text. DE4 This is the second4 text. GH4 9.9.7890 Now I need to grep for GH1, 2, 3 ,4 records and extract the corresponding number upto 5 position.. i.e GH1 9.8.7, GH2 19.8.7...like this so on....and I have to add these number into another along with a text to the top. For example, in my file1.txt...I need to add like this... The world is round 9.8.7 Today is my birthday 19.8.7 like this...I need to do it...Pls help on this... |
|
||||
|
Code:
BEGIN {
FS="[ .]"
}
/GH[12]/ {
str = $1=="GH1" ? "The world is round" : "Today is my birthday"
printf "%s %s.%s.%.1s\n", str, $2, $3, $4
}
Code:
awk -F'[ .]' '/GH[12]/ {str=$1=="GH1"?"The world is round":"Today is my birthday";printf "%s %s.%s.%.1s\n",str,$2,$3,$4}' your.file
|
| Sponsored Links | ||
|
|