Help with saving file in desired format


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with saving file in desired format
# 1  
Old 04-02-2012
Question Help with saving file in desired format

Hi

I have the following file in the unix named emp.

Code:
ID,NAME,SAL,DEPT
101,aaa,2000,10
102,bbb,3000,20
103,ccc,4000,30
104,ddd,5000,40
105,aaa,2000,50
106,bbb,3000,60
107,ccc,4000,70
108,ddd,5000,10
109,aaa,2000,80

I need to save first 3 columns(ID, NAME, SAL) in another file with .txt format.I have used cut command as follows.

Code:
cut -d ","  | -f 1,2,3 emp > employee.txt

this command worked in cutting first three columns but the problem is the fields are coming in a straight line in "employee.txt" as follows

Code:
101,aaa,2000,10 102,bbb,3000,20 103,ccc,4000,30 104,ddd, 5000,40105,aaa,2000,50 106,bbb,3000,60

but i want the fields to be arranged like it was arranged in unix file like a table.

Plz help me in this regard.

Last edited by methyl; 04-02-2012 at 11:58 AM.. Reason: please use code tags
# 2  
Old 04-02-2012
Is that an extra pipe symbol, or a missing command?
# 3  
Old 04-02-2012
Try without the extra pipe character.
Code:
cut -d "," -f 1,2,3 emp > employee.txt

If that doesn't work, please post this diagnostic output so we can see the format of the input file:
Code:
sed -n l emp

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Desired Date format

I need to get the current year for the files that has been created today. Ex- when i list in unix console it shows ls -l abc.txt -rw-rw-r-- 1 user1 user1 33 May 2 08:58 abc.txt but i need to get as May 2 2013 , i dont need 08:58 is there any command to list it out in that... (7 Replies)
Discussion started by: Prashanth B
7 Replies

2. UNIX for Dummies Questions & Answers

How to print the line from the file in the desired format:?

I am reading a file of Linux ( like mentioned below) & the data is represented in a single line like mentioned below: 11/03 4:00 39992 0.098 5.195 0.034 0.001 1.091 182 0.000 0 0.071 4.252 0.033 0.001 666.53 Now i want to print the result in other file something like this :- 39992... (5 Replies)
Discussion started by: Anamica
5 Replies

3. Shell Programming and Scripting

handling CSV file to get desired output

Hi All , i have a CSV file , pattern is given below :- Group # name # host # account # stop # # start # # check -------------------------------------------------------------------------- file format and data exmaple :- RBP2,RB0112,sihrb001,tksrb011,. ./.profile 1>/dev/null 2>&1;stop_olc_dmn... (0 Replies)
Discussion started by: deepakiniimt
0 Replies

4. Shell Programming and Scripting

Need your help to get the output of the list in desired format

Hello Guys, I am working on a script and using the below code to fetch the list of all repositories CHDIR='/mnt/scm/subversion/' repolist() { cd ${CHDIR} Repo=`ls|cut -d " " -f1` echo $Repo } Output of the above code is BSB CIB COB DCI DIB DSB ESB-P ESB-TOOLS FareVerify GCACHE GWY... (15 Replies)
Discussion started by: rohit22hamirpur
15 Replies

5. Shell Programming and Scripting

Newbie.. Find if a file exists and open, if not create the desired file..

Hey all, I'm brand new to script writing, I'm wanting to make a script that will ask for a file and then retrieve that file if it exists, and if it doesn't exist, create the file with the desired name, and I'm completely stuck.. so far.. #! bin/bash echo "Enter desired file" read "$file" if ... (5 Replies)
Discussion started by: Byrang
5 Replies

6. Shell Programming and Scripting

HELP: I need to sort a text file in an uncommon manner, can't get desired results

Hi All I have a flat text file. Each line in it contains a "/full path/filename". The last three columns are predictable, but directory depth of each line varies. I want to sort on the last three columns, starting from the last, 2nd last and 3rd last. In that order. The last three columns... (6 Replies)
Discussion started by: JakeKatz
6 Replies

7. Shell Programming and Scripting

Formatting of file to an desired one

Hi, I am trying to format an existing file to the desired format. Existing file : abc.txt 2332 |3322 |5534 |5436 |NULL | Desire file : QTD GROSS|2332 |3322 |5534 |5436 | echo "QTD GROSS|" > out.xt cat abc.txt | cut... (5 Replies)
Discussion started by: pkondur
5 Replies

8. HP-UX

Desired Format !

Hi everybody, I just need desired ouput from text file which should have folowing format; "2007-06-25 00:03:32.926+05:30",12354369,"Load","Completed","Rs.-5,556.00",9452217714 "2007-06-25 00:06:57.357+05:30",12354371,"Load","Completed","Rs.-56.00",9415766266 "2007-06-25... (1 Reply)
Discussion started by: prasanth_babu
1 Replies

9. UNIX for Advanced & Expert Users

get the timestamp of a file in desired format

Hi, I have a file say abc. I get the timestamp in following way: ls -ltr abc | awk -F" " '{print $6,$7,$8}' Mar 8 10:23 I need to get the timestamp as : 03-08-2007 10:23:00 Thanks Sumeet (1 Reply)
Discussion started by: sumeet
1 Replies

10. UNIX for Dummies Questions & Answers

capturing the time stamp in desired format

Hello All, I am working on korn shell script.i have 2 questions; 1) I have a file and i am able to capture the arrival time. the arrival time is capturing as 11:30 ls -ltr aaa.bbb.332121312.*.* | awk -F" " '{print $8}' 11:30 my desired output is 113000 can anyone please suggest me... (2 Replies)
Discussion started by: pavan_test
2 Replies
Login or Register to Ask a Question