Manipulation of a list


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Manipulation of a list
# 1  
Old 01-03-2012
Manipulation of a list

I have a list of file names, such as below

Code:
n02-z30-dsr65-terr0.50-dc0.002-8x6drw-csq.msf
n02-z30-dsr65-terr0.50-dc0.006-8x6drw-csq.msf
n02-z30-dsr65-terr0.50-dc0.010-8x6drw-csq.msf
n02-z30-dsr65-terr0.50-dc0.004-8x6drw-csq.msf
n02-z30-dsr65-terr0.50-dc0.008-8x6drw-csq.msf

I want to create
Code:
n02-z30-dsr65-terr0.50-dc0.008-8x6drw-csq.msf

Basically I want to remove the dc tag from the list, then do a sort so that I end up with the common name irrespective of the dc value.

Currently I have coded:
Code:
echo "n02-z30-dsr65-terr0.50-dc0.002-8x6drw-csq.msf n02-z30-dsr65-terr0.50-dc0.006-8x6drw-csq.msf n02-z30-dsr65-terr0.50-dc0.010-8x6drw-csq.msf n02-z30-dsr65-terr0.50-dc0.004-8x6drw-csq.msf n02-z30-dsr65-terr0.50-dc0.008-8x6drw-csq.msf" | tr ' ' '\n' | awk 'BEGIN{FS="-";OFS="-"} {$5=""; print }'

and I end up with

Code:
n02-z30-dsr65-terr0.50--8x6drw-csq.msf
n02-z30-dsr65-terr0.50--8x6drw-csq.msf
n02-z30-dsr65-terr0.50--8x6drw-csq.msf
n02-z30-dsr65-terr0.50--8x6drw-csq.msf


Now I am thinking of replacing the "--" with "-", then do a sort.

I have tried using

Code:
awk '{gsub(/--/, "-")}'

which is not working

Last edited by kristinu; 01-03-2012 at 05:16 PM..
# 2  
Old 01-03-2012
Code:
awk -F"-" '{OFS="-"; print $1,$2,$3,$4,$6,$7}' $listfile

# 3  
Old 01-03-2012
Howabout using the unix "cut" command.

Code:
cat filename.txt | cut -f1-4,6- -d-

n02-z30-dsr65-terr0.50-8x6drw-csq.msf
n02-z30-dsr65-terr0.50-8x6drw-csq.msf
n02-z30-dsr65-terr0.50-8x6drw-csq.msf
n02-z30-dsr65-terr0.50-8x6drw-csq.msf
n02-z30-dsr65-terr0.50-8x6drw-csq.msf

I might have missed something here but I can't see the point of a sort because all the results are the same. Maybe you mean sort then uniq.
# 4  
Old 01-03-2012
Quote:
Originally Posted by methyl
Code:
cat filename.txt | cut -f1-4,6- -d-

oh, no! UUOC alert! Smilie

try ...
Code:
cut -f1-4,6- -d- filename.txt

# 5  
Old 01-03-2012
Please do not ever mention UUOC in my presence. That is unless you can write software to get data onto a pipeline faster than "cat".

Last edited by methyl; 01-03-2012 at 08:01 PM.. Reason: removed insult!
# 6  
Old 01-03-2012
you could use cut directly on the file ... try the code i wrote ... tested on solaris 10 and centos ...

btw, the name calling was uncalled for.
# 7  
Old 01-03-2012
Apologies (insult removed from post) because I can see that you are an experienced poster. There are many who jump on the "cat" command because they have seen other uninformed posts. They do not take into account the quality of the read routine within the program. The read routine of the "cut" program is not of the same raw quality as "cat".
I do take offence to posters who post alternative code where there is no benefit whatsoever from not using "cat".

Just in case it is better on your O/S, try "timex" on a decent sized file.

Last edited by methyl; 01-03-2012 at 08:00 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

String manipulation.

If a have a variable with a first and last name. and say the variable looks like this... FIRST LAST how could process the variable to look like First .L bash 3.2 (osx) (3 Replies)
Discussion started by: briandanielz
3 Replies

2. Shell Programming and Scripting

File manipulation

Hi, My requirement is that ,i need to generate data file consisting of very high number of transactions. I need to take the header for the file containing pipe delimited columns from a different file(Header.txt containing headers for different formats).Please help me in this regard. Also for... (5 Replies)
Discussion started by: krashraj
5 Replies

3. UNIX for Dummies Questions & Answers

Help with file manipulation

Dear All, I have a question. So for the following sample file I would like to collect information about entries in $F, $F & $F so as to acheive the following output as shown below SK1.chr01 854 levure5 A G 225 . ... (7 Replies)
Discussion started by: pawannoel
7 Replies

4. UNIX for Dummies Questions & Answers

Data Manipulation

Hello I am currently having problems in mapulating a certain file which contains vaious data. Belos is a sample content Event=<3190> Client IP=<151.111.11.143> DNS=<abc.sbc.com> TransCount=<139> Client IP=<150.222.133.163> DNS=<xyz.yuu.com> TransCount=<3734> Event=<3120> Client... (11 Replies)
Discussion started by: khestoi
11 Replies

5. Shell Programming and Scripting

Splitting a list @list by space delimiter so i can access it by using $list[0 ..1..2]

EDIT : This is for perl @data2 = grep(/$data/, @list_now); This gives me @data2 as Printing data2 11 testzone1 running /zones/testzone1 ***-*****-****-*****-***** native shared But I really cant access data2 by its individual elements. $data2 is the entire list, while $data,2,3...... (1 Reply)
Discussion started by: shriyer
1 Replies

6. UNIX for Dummies Questions & Answers

text manipulation

I am tryin to figure out how to extract interested text from file example.txt blah blah blah a: child1 blah a: child2 blah b: parent1 blah blah blah .... blah a: child21 blah a: child22 blah a: child23 blah b: parent2 this kinda text repeats .. number of children is... (6 Replies)
Discussion started by: rajkishore
6 Replies

7. Shell Programming and Scripting

Date Manipulation

I need to achieve the following.....I seached the forum but could not find it... This is I have in a file... "CH","TIA","10/27/2006",000590 I need the date in the third field to be attached to fileas 20061027_test.txt How do I do it. (6 Replies)
Discussion started by: mgirinath
6 Replies

8. Shell Programming and Scripting

Subtract 100 from first field in long list? Simple manipulation?

It sounds so easy to do. I have a file thats laid out like this.. number text text text text (etc about 15 times with various text fields) I want to take the first field, "number", subtract 100 from it, and then put it back in the file. a simple little manipulation of the first field in... (4 Replies)
Discussion started by: LordJezo
4 Replies

9. UNIX for Dummies Questions & Answers

manipulation

hi, i have got a table with n number of rows and 2 columns..how can i get get 1 row at a time using any unix command without copying to any file? Thanks and Regards vivek.s (13 Replies)
Discussion started by: vivekshankar
13 Replies

10. Shell Programming and Scripting

File Manipulation

Hi, I am trying to manipulate a file that looks something like below: ! 7788 |778855 |SCOTT | ! 7782 |778223 |CLARK | ! 7902 |790245 |FORD | ! 7698 |7698455 |BLAKE | ! 7934 |79345767 |MILLER | ! 7844 |784 |TURNER |... (1 Reply)
Discussion started by: rkumar28
1 Replies
Login or Register to Ask a Question