split word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting split word
# 1  
Old 09-15-2011
split word

Hi all,

Infile:
Code:
1|2|3|test james ke the one |value
1|2|3|test the value|comp
1|2|3|test james|value
1|2|3|one two three|value

I need split the 4th delimiter value into 3 fields based on below condition.if 4th field contains "ke loc" or "the" then i should not consider it is word and need to take following word also
otherwise take it is word and write in output file separated by |

Expected outfile :
Code:
1|2|3|test|james|ke the one |value
1|2|3|test|the value||comp
1|2|3|test|james|||value
1|2|3|one|two|three|value

Thanks in advance.

Moderator's Comments:
Mod Comment Please use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks. See your PMs. According to the amount of posts you have you should know better. Ignoring this over time will result in a ban so consider if this is worth it, thanks.

Last edited by zaxxon; 09-15-2011 at 08:08 AM.. Reason: code tags, see PM
# 2  
Old 09-15-2011
hmm, you still not following the [code] rules Smilie

Please use the [CODE] tags
# 3  
Old 09-15-2011
Sorry. Next time onwards I will follow CODE tags .

---------- Post updated at 08:42 AM ---------- Previous update was at 06:15 AM ----------

Any help
# 4  
Old 09-15-2011
what u tried so far ?
# 5  
Old 09-15-2011
I tried some of the awk command combination. But no luck sir.
# 6  
Old 09-17-2011
Code:
# awk -F'[ |]' '{for(i=0;++i<=NF;){if($i){printf $i ((i==NF)?ORS:($i~"the|ke")?OFS:"|")}}}' file
1|2|3|test|james|ke the one|value
1|2|3|test|the value|comp
1|2|3|test|james|value
1|2|3|one|two|three|value

This User Gave Thanks to danmero For This Post:
# 7  
Old 09-17-2011
Thanks Danmero. It is working now.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

2. UNIX for Dummies Questions & Answers

Split word

Hi, I have file like below NN3EN3 UKLND JESSICA PETER BANK SYSTEMS BANK SYSTEMS 21514 LON PROJECT LEADPROJECT LEAD 340934742 PETER N34ZG4 UKLND SCOTT TAILER PEOPLE CORP... (1 Reply)
Discussion started by: stew
1 Replies

3. Shell Programming and Scripting

awk to split one field and print the last two fields within the split part.

Hello; I have a file consists of 4 columns separated by tab. The problem is the third fields. Some of the them are very long but can be split by the vertical bar "|". Also some of them do not contain the string "UniProt", but I could ignore it at this moment, and sort the file afterwards. Here is... (5 Replies)
Discussion started by: yifangt
5 Replies

4. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

5. Programming

import .txt and split word into array C

Hi, if I want to import .txt file that contain information and the number separate by space how can I split and put into array In C Example of .txt file 3 Aqaba 49789 10000 5200 25.78 6987 148976 12941 15.78 99885 35262 2501 22.98 Thank (3 Replies)
Discussion started by: guidely
3 Replies

6. Shell Programming and Scripting

How do you split a sentence after every nth word

Hi, I think my problem is a "simple" one to resolve. What i am looking for is a way in sed/awk to split a long line/paragraph into say 5 words per line. For example: Sentence/paragraph contains: 102 103 104 105 106 107 109 110 .... I would like the output to be (if splitting every 5... (5 Replies)
Discussion started by: muay_tb
5 Replies

7. Solaris

Split a file which a word criteria in two files with awk

Hello, I'm searching with the Awk command to split a file into two others files. I explain : in the file N°1 I search the word "NameVirtual" and since that word to the end of the file I want to store all lines in a new file N°2 Also from that word to the beginning of the file I want to... (11 Replies)
Discussion started by: steiner
11 Replies

8. Shell Programming and Scripting

Split a word in short words

Dear, Can somebody help me with this? I have a variable TGT=T2DIRUPDAZ20070326VA I want to get in variables some part of TGT. like this. TGT1=UPDA TGT2=20070326 TGT3= VA These three variables have fixe position in variable TGT. (2 Replies)
Discussion started by: yeclota
2 Replies

9. UNIX for Dummies Questions & Answers

Split a file with no pattern -- Split, Csplit, Awk

I have gone through all the threads in the forum and tested out different things. I am trying to split a 3GB file into multiple files. Some files are even larger than this. For example: split -l 3000000 filename.txt This is very slow and it splits the file with 3 million records in each... (10 Replies)
Discussion started by: madhunk
10 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question