Manipulating files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Manipulating files
# 1  
Old 03-10-2011
MySQL Manipulating files

Hi Guys,
I'm really new to Unix and Linux and other scripting languages but recently I hv been really enthusiatic about learning more to help out on my work.
So I have a file with 3 columns. A sample of it looks like looks like this :
K2_537841 AAATCAGCCGCAACATTTGC AACCACCTGCCTTTGTTTCC
K2_793131 AGAAGGTCGGGGACTTCTTC CCTGAGTGAGCGCATATTGC
K4_631836 GGACAATACACGCCAATCTG TTGATTCTTCCTGGCGGTAG
K7_478339 GCGGCCAACAATGTAACCTT GGTGGCCTGGCATAATAGGA
K8_337205 CTGCAGACCTGGAGTTCCAA GGACCCATTTATGGGTTTCC
K10_583020 AATGCCATTGACCGTTTGAG TAACTACTGACGCAGCAGAC
K12_175548 CTTCTCCGCAATGGAGAGAG GTATGGCACTTCGACTTTCG
K13_93992 GCAAGTCAGGGTTCTCATCG AAGTGGATCCTTCCGGTTCC
K15_400245 GTTAATGCCCGACACCCTAG AGCCAGAAAATGACGCACTG
K15_691640 GAAGACGACCGTTCGTCTTC TTGTGCGCCTGTTTCTGATG


Now what I need doing is using command line/script I want to duplicate each entry in the first column and place it in the line below. Then I need to rename the first one usinf _Fw and the second one as _Rev. Its gets more complicated. Then each entry in column 2 to be placed in front of the _Fw named fields and each entry in column 3 to be placed in front the _Rev named fields.

Can someone please help or suggest ways. Again I'm a newbie so even basic comments will be very much appreciated.

Thanks and hope to hear from you all.

Have a nice day Smilie

Pawan
# 2  
Old 03-10-2011
Post desired output for those sample lines.
# 3  
Old 03-10-2011
K2_537841_Fw AAATCAGCCGCAACATTTGC
K2_537841_Rev AACCACCTGCCTTTGTTTCC
K2_793131_Fw AGAAGGTCGGGGACTTCTTC
K2_793131_Rev CCTGAGTGAGCGCATATTGC
K4_631836_Fw GGACAATACACGCCAATCTG
K4_631836_Rev TTGATTCTTCCTGGCGGTAG
K7_478339_Fw GCGGCCAACAATGTAACCTT
K7_478339_Rev GGTGGCCTGGCATAATAGGA
K8_337205_Fw CTGCAGACCTGGAGTTCCAA
K8_337205_Rev GGACCCATTTATGGGTTTCC
K10_583020_Fw AATGCCATTGACCGTTTGAG
K10_583020_Rev TAACTACTGACGCAGCAGAC
K12_175548_Fw CTTCTCCGCAATGGAGAGAG
K12_175548_Rev GTATGGCACTTCGACTTTCG
K13_93992_Fw GCAAGTCAGGGTTCTCATCG
K13_93992_Rev AAGTGGATCCTTCCGGTTCC
K15_400245_Fw GTTAATGCCCGACACCCTAG
K15_400245_Rev AGCCAGAAAATGACGCACTG
K15_691640_Fw GAAGACGACCGTTCGTCTTC
K15_691640_Rev TTGTGCGCCTGTTTCTGATG
# 4  
Old 03-10-2011
Try:
Code:
perl -alne 'print "$F[0]_Fw $F[1]";print "$F[0]_Rev $F[2]"' file

This User Gave Thanks to bartus11 For This Post:
# 5  
Old 03-10-2011
Awesome this worked exactly like I wanted it to ....... thanks a lot

Could you please explain the code /..... for example I dont know what perl -alne does and I can make sense of the $F which if I'm right means field !! ?? ... I'llreally appreciate that

Cheers and thanx again

Smilie
# 6  
Old 03-10-2011
Here comes short description of those switches:
  • -a: split line into array @F, using space as default separator, so fields can be accessed as: 1st field - $F[0], second field $F[1], etc
  • -l: it has many effects, one of them is adding newline at the end of each "print" statement, so I don't have to write print $F[0]_Fw $F[1]\n"
  • -n: don't print line after executing script
  • -e: execute script that follows
To learn more about Perl's options check
Code:
man perlrun

This User Gave Thanks to bartus11 For This Post:
# 7  
Old 03-14-2011
awk version

awk '{print $1 "_Fw " $2 "\n" $1 "_Rev " $3}' <input_file >output_file
This User Gave Thanks to sgruenwald For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Manipulating files

Not sure if the question posted in another forums can be moved by me.So posting the link here. https://www.unix.com/unix-advanced-expert-users/221425-shell-script-manipulate-files.html#post302795379 Need your help here. (1 Reply)
Discussion started by: vedanta
1 Replies

2. Shell Programming and Scripting

Manipulating audio files server side

Hi All, I have next to zero knowledge on what I am about to ask so I will just ask it in plain English :) I am wondering how best to go about manipulating audio files server side. The manipulations required are join files one after the other, eg, audio1 + audio2 + audio3 + audio4 = audio5 ... (0 Replies)
Discussion started by: linuxgoat
0 Replies

3. Shell Programming and Scripting

Manipulating Columns!

Hello Experts, I have .txt file which has various columns and 4 rows. cat input.txt Cont x y z k Max 0.3 0.9 0.4 0.6 Min 0.2 0.9 0.3 0.6 Diff 0.1 0 0.1 0 Output: Cont x y z k Max 0.5 1.1 0.6 0.8 Min 0.1 0.7 0.2 0.4 Diff 0.4 0.4 0.4 0.4 That means if the diff between the Max and... (2 Replies)
Discussion started by: dixits
2 Replies

4. Shell Programming and Scripting

copying and manipulating files

im copying alot of files this is a script im trying to modify but not sure how to make it copy files without an extension and then add a .txt to them abc= #assuming the file does not have an end or extension foo='abc$' FROM=/user/share/doc TO=~/home/doc for grep $foo in... (3 Replies)
Discussion started by: elginmulizwa
3 Replies

5. Shell Programming and Scripting

reading from two files and manipulating the data

hi i have a file of the following format FILE1 5 937 8 1860 1850 1 683 2 1 129 2 2 5 938 8 1122 1123 1 20 520 4 1860 1851 1 5 939 8 1122 1124 1 20 521 4i have another file which... (3 Replies)
Discussion started by: vaibhavkorde
3 Replies

6. Shell Programming and Scripting

need help on manipulating a file

Hi, I need a shell/command to achieve this task. I've a delimited unloaded file from oracle in a scrambled format as shown below with many blank lines in it, I'm just trying to tailor it in a format that would be compatible to view and load it to a IDS db. Here is the problem ... (1 Reply)
Discussion started by: divak
1 Replies

7. Shell Programming and Scripting

Manipulating a file

Hi everybody, I need an urgent help with a BASH script. I have file which contains (besides the other data) the lines with the following structure identified by with keyword PCList: <PARAMETER NAME="PCList" TYPE="LIST_STRUCTURE" MODEL="{,}" ... (1 Reply)
Discussion started by: sameucho
1 Replies

8. Shell Programming and Scripting

csh: manipulating text files - please help!

Hi All, I am trying to manipulate a text file in a csh script I am writing. I just started scripting a few months ago and have NO idea how to get this to work. My ultimate goal is to turn a text file that looks like this: 4 ep2d_diff_mddw_20_p2-MOD err 128 128 64 62 52611737 2 ... (3 Replies)
Discussion started by: Torinator
3 Replies

9. Shell Programming and Scripting

Can I make "touch" create executable files by manipulating umask?

I'm getting to grips with this concept of the umask. What I thought was, setting umask uga+rwx would result in creating files with all permissions for everyone. Seems not to be the case though. Read and write bits get set, but not the execute bit. Is there some gap in my understanding, or is... (2 Replies)
Discussion started by: tphyahoo
2 Replies

10. UNIX for Advanced & Expert Users

Manipulating two files

Hi Friends, I prefer to represent my problem with example. I have two files as below: file1.txt --------- abcd.....1234......XY abcd.....1235......XX abcd................. abcd...231236..1111YX abcd...241236..1112YY abcd...241237......YY abce.....1235......YY file2.txt ------- ... (4 Replies)
Discussion started by: rinku11
4 Replies
Login or Register to Ask a Question