Simple script to write new lines in a text file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Simple script to write new lines in a text file
# 15  
Old 05-26-2012
Quote:
Originally Posted by bartus11
Can you post output of:
Code:
cat -e file | head

Yea something weird is going on...file is fine when I open in excel. This is what the cat looks like

Code:
jonathon-torchias-macbook-pro:Desktop torchiaj$ cat -e test2.txt | head
Gene Name	sdfad	ATRT prev seen (formatted)	UniProt ID	sdfs	NCBI Accession	UCSC Link	Cosmic Gene	Variation	Position	Ref	Alt	AA Length^MA1BG	P04217	ATRT_SP192	P04217	NM_130786	NM_130786	UCSC link	CosLink	nonsynonymous SNV	chr19:58861808	A	G	495^MA1CF	Q9NQ94	"ATRT47B,ATRT47"	Q9NQ94	NM_014576	NM_014576	UCSC link	CosLink	nonsynonymous SNV	chr10:52573772	C	T	594^MA1CF	Q9NQ94	ATRT41	Q9NQ94	NM_014576	NM_014576	UCSC link	CosLink	nonsynonymous SNV	chr10:52566611	C	T	594^MA2M	P01023	ATRT41	P01023	NM_000014	NM_000014	UCSC link	CosLink	nonsynonymous SNV	chr12:9258857	C	T	1474^MA2M	P01023	"ATRT12B,ATRT12"	P01023	NM_000014	NM_000014	UCSC link	CosLink	nonsynonymous SNV	chr12:9254209	T	C	1474^MA2M	P01023	ATRT64	P01023	NM_000014	NM_000014	UCSC link	CosLink	nonsynonymous SNV	chr12:9222373	T	G	1474^MA2M	P01023	ATRT63	P01023	NM_000014	NM_000014	UCSC link	CosLink	nonsynonymous SNV	chr12:9260170	C	T	1474^MA2M	P01023	"ATRT2B,ATRT2,ATRT39,ATRT40"	P01023	NM_000014	NM_000014	UCSC link	CosLink	nonsynonymous SNV	chr12:9243017	G	A	1474^MA2ML1	A8K2U0	ATRT67	A8K2U0	NM_144670	NM_144670	UCSC link	CosLink	nonsynonymous SNV	chr12:8976358	C	G	1454^MA2ML1	A8K2U0	ATRT63	A8K2U0	NM_144670	NM_144670	UCSC link	CosLink	nonsynonymous SNV	chr12:9027033	A	G	1454^MA2ML1	A8K2U0	ATRT33	A8K2U0	NM_144670	NM_144670	UCSC link	CosLink	nonsynonymous SNV	chr12:9004388	G	A	1454^MA2ML1	A8K2U0	"ATRT8B,ATRT8"	A8K2U0	NM_144670	NM_144670	UCSC link	CosLink	nonsynonymous SNV	chr12:9000236	G	A	1454^MA2ML1	A8K2U0	ATRT34	A8K2U0	NM_144670	NM_144670	UCSC link	CosLink	nonsynonymous SNV	chr12:9013737	A	G	1454jonathon-torchias-macbook-pro:Desktop torchiaj$

# 16  
Old 05-26-2012
You have to get rid of the Windows newline characters:
Code:
tr '\r' '\n' < file > file.fixed

# 17  
Old 05-26-2012
In addition to transforming the classic Mac line breaks, there needs to be a space between -v and OFS, and field 3 contains double quotes that need to be removed and FS is best also set to "\t" in this TAB-delimited file...

Last edited by Scrutinizer; 05-26-2012 at 07:40 PM..
# 18  
Old 05-27-2012
Try this:
Code:
awk '$3~/,/{n=split($3,T,/[,"]*/); for (i=2;i<n;i++) {$3=T[i]; print}next}1' FS='\t' OFS='\t' infile


Instead of a separate conversion step (with tr '\r' '\n') it could also be done by setting RS:
Code:
awk '$3~/,/{n=split($3,T,/[,"]*/); for (i=2;i<n;i++) {$3=T[i]; print}next}1' RS='\r' FS='\t' OFS='\t' infile

# 19  
Old 05-27-2012
That looks like it worked! Thanks guys for the help.
Much appreciated!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

Simple script to test mountGpoint for read-write

Guys, need your help urgently. ServerA ServerB ServerA has an email facility and can connect remotely via root using key to ServerB What I am trying to achieve here is ServerA would be able to remotely: 1. Do command 'touch /mnt/testfile.date' on ServerB 2. If touch failed with... (4 Replies)
Discussion started by: jaapar
4 Replies

3. Shell Programming and Scripting

Need help to write a shell script to convert text file to excel file.

Hi Everyone, I want your help to write a script which will take text file as input and on the basis of delimiter ":"script will create excel sheet. Example input: IpAdress:InstanceName:Port:ServerName 10.255.255.1:abc:2232:xyz_abc Output should be an excel sheet like below: Column... (8 Replies)
Discussion started by: akabhinav18
8 Replies

4. Shell Programming and Scripting

Bash script - printing range of lines from text file

I'm working on a new exercise that calls for a script that will take in two arguments on the command line (representing the range of line numbers) and will subsequently print those lines from a a specified file. Command line would look like this: ./lines_script.bash 5 15 <file.txt. The script would... (8 Replies)
Discussion started by: ksmarine1980
8 Replies

5. Shell Programming and Scripting

How to write text file data to excel using UNIX shell script?

Hi All, I have the requirement in unix shell script. I want to write the "ls -ltr" command out put to excel file as below. Input :text file data : drwxr-xr-x 5 root root 4096 Oct 2 12:26 drwxr-xr-x 2 apx aim 4096 Nov 29 18:40 drwxr-xr-x 5 root root 4096 Oct 2 12:26 drwxr-xr-x... (10 Replies)
Discussion started by: Balasankar
10 Replies

6. Shell Programming and Scripting

how to write multiple lines to a file using shell script?

I need to create an xml using shell script, but i first want to know how can i write multiple lines to file using shell script? (7 Replies)
Discussion started by: vel4ever
7 Replies

7. Shell Programming and Scripting

How to write a script for text file encryption?

Hi All, I have zero knowledge in UNIX, so i desperately need the help from you guys. I need a script which can encrypt all the text files in one shot in a source directory. After all the text files are encrypted, they will be put into a separate folder. Command involve: gpg with -a,... (6 Replies)
Discussion started by: shanbalao
6 Replies

8. Shell Programming and Scripting

looking for a script that will delete lines in a text file

it will grep for a line and then delete these line. how do i begin to write this script if theres no available one? (3 Replies)
Discussion started by: garfish
3 Replies

9. Shell Programming and Scripting

how to write shell script to extract lines we want

hi i have a file which is very large . it contains lines in the format below: seed url, html url .... ... seed url, html url i have sort it already. 2010ÄÏ·ÇÊÀ½ç±*_¾º¼¼·ç±©_ÐÂÀËÍø ÕżªÁúרÀ¸£ºÊÀ½ç±*24ÄêµÄ»ØÒä ÆÚÅÎÑÇÖÞδÀ´ÍŽá_2010ÄÏ·ÇÊÀ½ç±*_¾º¼¼·ç±©_ÐÂÀËÍø 2010ÄÏ·ÇÊÀ½ç±*_¾º¼¼·ç±©_ÐÂÀËÍø ¹úÃ×Óë±´ÄáÌØ˹´ï³ÉÐ*Òé... (6 Replies)
Discussion started by: rainboisterous
6 Replies

10. Shell Programming and Scripting

Shell script to read lines in a text file and filter user data

hi all, I have this file with some user data. example: $cat myfile.txt FName|LName|Gender|Company|Branch|Bday|Salary|Age aaaa|bbbb|male|cccc|dddd|19900814|15000|20| eeee|asdg|male|gggg|ksgu|19911216||| aara|bdbm|male|kkkk|acke|19931018||23| asad|kfjg|male|kkkc|gkgg|19921213|14000|24|... (4 Replies)
Discussion started by: srimal
4 Replies
Login or Register to Ask a Question