Script to edit a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to edit a text file
# 1  
Old 06-07-2013
Script to edit a text file

hi, could someone share a short script that would process a .txt file and do the following, for example the text file has this form

0:1.0 1:1.0 2:2.0 3:3.0 4:4.0 5:5.0 6:6.0 7:7.0 8:8.0 ... {newline}
9:9.0 10:10.0 11:11.0 12:12.0 13:13.0 14:14.0 15:15.0 16:16.0 17:17.0 ... {newline}


and I would like the number before the column to be removed and the number after the column from float format to be converted in integer format and the newline to be respected, like:

1 2 3 4 5 6 7 8 ... {newline}
9 10 11 12 13 14 15 16 17 ... {newline}


Please note the {spaces} in between are important to be respected.

thank you very much!
# 2  
Old 06-07-2013
Try:

Code:
sed 's/[0-9]*://g;s/\.[0-9]*//g' inputfile

This User Gave Thanks to hergp For This Post:
# 3  
Old 06-07-2013
Code:
perl -lane 'for(@F){s/\d+?:(\d+?)\.\d+/$1/}; print "@F"' file

Code:
sed 's![^:]*:\([0-9]*\)\.[0-9]*!\1 !g' file

This User Gave Thanks to balajesuri For This Post:
# 4  
Old 06-07-2013
With awk
Code:
awk '{gsub(/[0-9]*:/,"");gsub(/\.[0-9]*/,"")}1'

This User Gave Thanks to Jotne For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

File edit script exceptions how to pass to script

i wrote script for if file exists script do file edit problem with the script get stuck not existing as for exit i mentioned exit 0 , and how to give the exception for script it should add ./script -- add hi ./script --add "hi how are you" now below script with case it is working for... (0 Replies)
Discussion started by: markjohn1
0 Replies

2. Shell Programming and Scripting

Edit first line of a text file

Hi friends, Issue1: I have a text file with the first line like this #chrom start end Readcount_A Normalized_Readcount_A ReadcountB Normalized_Readcount_B Fc_A_vs_B pvalue_A_vs_B FDR_A_vs_B Fc_B_vs_A pvalue_B_vs_A FDR_B_vs_A <a href="http://unix.com/">Link</a> How can I change it to the... (11 Replies)
Discussion started by: jacobs.smith
11 Replies

3. Shell Programming and Scripting

Open the file and edit/append the text

Hi i have a file like this mailboxnum 20 filename <to subsitute> fileloaction /home/dd234/ filetype txt in a directory i have set of files for ex: TT45.1.2 TT45.1.3 TT45.1.4 . . in for loop i have to take this files and subsitute one by one ex: (1 Reply)
Discussion started by: greenworld123
1 Replies

4. Shell Programming and Scripting

Loop through text file > Copy Folder > Edit XML files in bulk?

I have a text file which contains lines in this format - it contains 105 lines in total, but I'm just putting 4 here to keep it short: 58571,east_ppl_ppla_por 58788,east_pcy_hd_por 58704,east_pcy_ga_por 58697,east_pcy_pcybs_por It's called id_key.txt I have a sample folder called... (9 Replies)
Discussion started by: biscuitcreek
9 Replies

5. Shell Programming and Scripting

How to get awk to edit in place and join all lines in text file

Hi, I lack the utter fundamentals on how to craft an awk script. I have hundreds of text files that were mangled by .doc format so all the lines are broken up so I need to join all of the lines of text into a single line. Normally I use vim command "ggVGJ" to join all lines but with so many... (3 Replies)
Discussion started by: n00ti
3 Replies

6. Shell Programming and Scripting

Text editing script does everything but edit text.

I wrote this script to create and edit a large number of websites based on a template site and a collection of text files which have the relevant strings in them delimited by colons. I run it and the shell doesn't produce any errors, but when it gets to the for loop where it actually has to edit... (2 Replies)
Discussion started by: afroCluster
2 Replies

7. UNIX for Dummies Questions & Answers

edit this text file

hi, i need to remove the first column (and dash) from this text file. Is there any unix command allowing me to do it ? 1-16 2-28 3-16 4-20 5- 8 6-32 7-19 8-16 9-27 10- 7 11-14 12-18 thanks (2 Replies)
Discussion started by: aneuryzma
2 Replies

8. Shell Programming and Scripting

Edit other than the first and last record of a text file

Hello, I have to add the string "YES" to the end of all records of files in a dir other than the first(header) and the last(trailer) record. viz, the first and the last record in a file has to be identified and exempted from the edit. I tried an awk script. But there seems to be no direct... (8 Replies)
Discussion started by: rogersed
8 Replies

9. Shell Programming and Scripting

How to EDIT file using VI in a script

Hello, How would i go about editing a file using VI within a shell script please? Basically, i want to open a file, clear it's contents and save the file. I found this on the web using "ex" but can't seem to get it to work: ex /home/oconnor/TOOLS/UNIXCMDS/test_ex <<eof_ex dd /*i put... (2 Replies)
Discussion started by: bobk544
2 Replies

10. Shell Programming and Scripting

Edit and insert character in a text file

Hello All, Can somebody please help me how to accomplish the following : I have a text file called data.txt that has the following information : M|88494-998494 M|98jd#0094 M|88394-994049 M|GFG9980#009944 and so on... I need to replace the value of M to either "S" or "X"... (3 Replies)
Discussion started by: negixx
3 Replies
Login or Register to Ask a Question