Cutting a portion of a line seperated by pipe delimiter


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Cutting a portion of a line seperated by pipe delimiter
# 1  
Old 06-21-2008
Cutting a portion of a line seperated by pipe delimiter

Hi,

In the below line

a|b|10065353|tefe|rhraqs|135364|5347575
dgd|rg|4333|fhra|grhrt|46423|urdsgd

Here i want to cut the characters in between the second and third pipe delimiter and then between fifth and sixth delimiter and retain the rest of the line.

My output should be

a|b||tefe|rhraqs||5347575
dgd|rg||fhra|grhrt||urdsgd

How do i do this?
# 2  
Old 06-21-2008
save the data in a files called test.out
run this awk command from commnd line
awk -F "|" 'BEGIN{OFS="|"}{$3=" ";$6=" ";print}' test.out
# 3  
Old 06-21-2008
This there a way to do this using a cut command?

Because the columns to be cut will be there in another paramfile. I have fixed width file as well as pipe delimited file. In case of fixed width file i will read the position to be cut from the param file and use the below commands. This is done in a script.

position=`grep "abc.txt" $path/paramfile | awk '{print$2}'`
cut -c$position abc.txt > file2.txt

Structure of param file will be like

abc.txt 1-5,68-

In case of delimited files if the same approach could be followed it would be easy.Because for each and every delimited file, the columns to be cut may vary.Hence i cannot hard the position to be cut in your code.

In case the file is a delimited file then the param file will have the information of which columns have to be retained.

like

file2.txt 1,3,4,7-

Last edited by ragavhere; 06-21-2008 at 05:46 AM.. Reason: Delimited file parm file structure
# 4  
Old 06-21-2008
Can you please tell you requirement with one example it is not clear in your post.
If the fils is a delimeter file where the delimeter specified and in which column of parameter file ?

what is 68- ?? should it be 6-8 instead .... Make your requirement clear to assist you
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cutting values with delimiter

Hi All, I have a string with , delimiter america,finland,netherlands Now i want these values to be stored in file as below with newline character at end of each value america finland netherlands Regards Prasad (3 Replies)
Discussion started by: krishna_gnv
3 Replies

2. Shell Programming and Scripting

Cutting a string using more than one character as delimiter

Hi , I have a set of files in a folder which i need to cut in to two parts.... Sample files touch AE_JUNFOR_2014_MTD_2013-05-30-03-30-02.TXT touch AE_JUNFOR_2014_YTD_2013-05-30-03-30-02.TXT touch temp_AE_JUNFOR_2014_MTD_2013-05-30-03-30-02.TXT touch... (4 Replies)
Discussion started by: chillblue
4 Replies

3. Shell Programming and Scripting

Cutting a part of line till delimiter

here are the few scenarios... isoSizeKB text NOT NULL, reserved1 varchar(255), KEY `deviceId` (`deviceId`) `d5` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `dHead` enum('HistoryInfo','Diversion') COLLATE utf8_unicode_ci, `ePR` int(11) DEFAULT '0', PRIMARY KEY (`id`) ... (7 Replies)
Discussion started by: vivek d r
7 Replies

4. Shell Programming and Scripting

Convert comma seperated file to line seperated.

Hi, I have data like this. 1,2,3,4 Output required: 1 2 3 4 I am trying to use tr function but getting error. Help is appreciated. (6 Replies)
Discussion started by: pinnacle
6 Replies

5. UNIX for Dummies Questions & Answers

cutting columns if delimiter has more than one charecter (|^)

Hi All, I am having a file with the delimiter '|^'. File name:test_dlim.csv I want to cut the first field of this using awk command. I tried with the help of the following link:... (2 Replies)
Discussion started by: boopathyvasagam
2 Replies

6. Shell Programming and Scripting

Cutting out text from specific portion on filename

Hi, how do I go about cutting out the first numeric characters after the word "access"? access1005101228.merged-00.15.17.86.d8.b8.log.gz (16 Replies)
Discussion started by: GermanJulian
16 Replies

7. Shell Programming and Scripting

Trimming fields for comma or pipe seperated file

I have file like this FileA: abc , "helloworld" , america def,asia, japan ghi, africa, ipl Output Needed: abc,"helloworld",america def,asia,japan ghi,africa,ipl I would like to implement using awk. I want to trim each field for its leading and trailing spaces. (7 Replies)
Discussion started by: pinnacle
7 Replies

8. Shell Programming and Scripting

Removing blank lines from comma seperated and space seperated file.

Hi, I want to remove empty/blank lines from comma seperated and space seperated files Thanks all for help (11 Replies)
Discussion started by: pinnacle
11 Replies

9. Shell Programming and Scripting

Cutting a tab delimiter file

I have a 30 column tab delimited record file. I need to extract the first 10column. The following command to cut was not working cut -f 1-10 -d "\t" filename. Could any one keep on this . Thanks in Advance (4 Replies)
Discussion started by: vinod.thayil
4 Replies

10. UNIX for Dummies Questions & Answers

cutting columns if delimiter has more than one charecter

Hi, My file looks like abc$%sdfhs$%sdf$%sdfaf$% here as seen delimiter is $%...now how cas i take out second field as cut command expect delimiter as single charecter only.....is there is any other way thanks and regards mahabunta (9 Replies)
Discussion started by: mahabunta
9 Replies
Login or Register to Ask a Question