Write to a file in a specified order


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Write to a file in a specified order
# 8  
Old 10-06-2010
It was a bug, so IBM fixed it! Maybe you reported it! It was useful -- we cannot have that! Smilie
# 9  
Old 10-08-2010
Hi,

I did not loop the awk script but found an easier solution like the one given below.
Right now it is working well on my AIX server.
But when i migrate the same to my LINUX server, its not executing.

Can anyone help..

Code:
pk1=1,3,2,4
mc1=6,5
pkcols1=`echo $pk1 | sed 's/,/,$/g'`
cols1=`echo $mc1 | sed 's/,/,$/g'`
awk -F, '{print'`echo "$"$pkcols1",$"$cols1`'}' OFS=, file1.txt

# 10  
Old 10-08-2010
Try nawk?
# 11  
Old 10-11-2010
I used the command dos2unix while moving the file from my windows to linux server and it worked perfectly Smilie

But i do want to know what exactly does this command do.. because when i transfer my file from windows to my AIX box, my code works fine even without converting.

Is this something specific to LINUX?

---------- Post updated at 09:25 PM ---------- Previous update was at 01:57 PM ----------

I am stuck up with yet another change to this code..

While the following code helps me to cut the columns in the required layout and create a new file, the file generated is comma separated. Is there a way where i can define which delimiter my output file should contain?

Code:
pk1=1,3,2,4
mc1=6,5
pkcols1=`echo $pk1 | sed 's/,/,$/g'`
cols1=`echo $mc1 | sed 's/,/,$/g'`
awk -F, '{print'`echo "$"$pkcols1",$"$cols1`'}' OFS=, file1.txt

I cannot use a sed and replace the comma with the delimiter i need, because my input file might contain comma in the data. SmilieSmilie

Last edited by Scott; 10-11-2010 at 02:30 PM.. Reason: Code tags, please...
# 12  
Old 10-11-2010
Quote:
I used the command dos2unix while moving the file from my windows to linux server and it worked perfectly

But i do want to know what exactly does this command do.. because when i transfer my file from windows to my AIX box, my code works fine even without converting.

Is this something specific to LINUX?
What usually matters is how you transfer the file. For example "ftp" in text mode will do the conversion for you. This is not specific to AIX or Linux.
# 13  
Old 10-12-2010
I recall it is mostly add/remove carriage returns before line feeds for dos and not for UNIX (but life also includes cr in place of lf for Apple, and then there is EBCDIC, unicode, UTF-8, . . . . ).
# 14  
Old 10-12-2010
@DGPickett

The line terminator for text files in unix is one character: linefeed.

The line terminator for text files in MSDOS is two characters: carriage-return, linefeed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File globbing order

Hi , I'm facing a different behaviour with one of my shell script for last few days. It was working good before that. here is my code for the script FileRemove.sh #get the file name# file1=$1 file2=$2 rm $file1 # delete the old file mv $file2 <target path> #move the new file to the target... (5 Replies)
Discussion started by: poova
5 Replies

2. Shell Programming and Scripting

Order of data in Spool File

Hello, I have a shell script through which I am executing .sql file and spooling the result of Query from .sql . I want to spool the result in ascending order. Is there any parameter to be set to print result in ascending or descending order. Thanks in advance. (4 Replies)
Discussion started by: Aparna.N
4 Replies

3. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

4. Shell Programming and Scripting

File listing in Ascending order

I have a multiple file with the following name like. file_0.csv file_1.csv file_2.csv file_3.csv file_4.csv file_5.csv file_6.csv file_7.csv file_7.csv file_8.csv file_9.csv file_10.csv file_11.csv file_12.csv file_13.csv file_14.csv (2 Replies)
Discussion started by: rakesh_arxmind
2 Replies

5. Solaris

Specifying file system mount order

Does anyone know if it's possible to specify the mount order of local and remote file systems? I'd like to mount a local ZFS file system on top of an NFS mount automatically and have that repeated on every reboot. I've checked man pages and Google, but can't find anything that addresses,... (6 Replies)
Discussion started by: Monty51
6 Replies

6. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

7. Shell Programming and Scripting

Order file by lines

My script(3 arguments $1 = folder,$2 extension,$3 string) should do the following things: -Enter in the folder of $1(if exists). -Put ls *.$2 > temp.txt ( I use a temp file to store the result of ls command and if $2 = txt in this file I'll have all the .txt files of the folder) -Now I want to... (2 Replies)
Discussion started by: Max89
2 Replies

8. Shell Programming and Scripting

sed or awk to order a file

Hi - I have a file with lots of lines in that I need to order based on the number of commas! e.g the file looks something like :- cn=john,cn=users,cn=uk,dc=dot,dc=com cn=john,cn=users,dc=com cn=users,cn=groups,dc=com cn=john,cn=admins,cn=users,cn=uk,dc=dot,dc=com... (4 Replies)
Discussion started by: sniper57
4 Replies

9. Shell Programming and Scripting

Reversing file order using SED

Im trying to develop a shell script that will change the content order of the file. For example I have a file that says a b c d I want to change this to be d c b a Im trying to use sed to this by reading the file and then inserting each line at the top #!/usr/bin/ksh ... (3 Replies)
Discussion started by: MBGPS
3 Replies

10. Shell Programming and Scripting

creating a file in reverse order of another file

Hi, I have a requirement where i need to write a script to create the new file from the given input file with the data in reverse order (bottom to top) Sample data: Input File-------------- Java VB Oracle Teradata Informatica Output file:----------------- Informatica Teradata Oracle... (3 Replies)
Discussion started by: srilaxmi
3 Replies
Login or Register to Ask a Question