Trim a file columnwise


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trim a file columnwise
# 1  
Old 07-02-2013
Trim a file columnwise

Hi All,

I want to trim each columns leading & trailing (like sql trim function) of a ',' separated file..

I've a file like this..

Code:
 manab , c  gi
   lucky , home 
 babu , maa

I want the output as

Code:
manab,c gi
lucky,home 
babu,maa

A one liner would be a great help.

Last edited by Scott; 07-02-2013 at 11:11 AM.. Reason: Please use code tags
# 2  
Old 07-02-2013
Code:
$ sed 's/^ *//g;s/ *,/,/g;s/, */,/g' a.txt
manab,c  gi
lucky,home 
babu,maa


Last edited by itkamaraj; 07-02-2013 at 11:29 AM..
# 3  
Old 07-03-2013
Thanks itkamaraj, this has worked. I've added another expression & made it complete.
Code:
sed 's/^ *//g;s/ *,/,/g;s/, */,/g;s/ *$//g' <filename>

Thank You,
Manab

Last edited by Franklin52; 07-03-2013 at 08:28 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

2. Shell Programming and Scripting

File comparison in UNIX columnwise

Hi all, I want to compare two files with same number of rows and columns with records in same order. Just want to highlight the differences in the column values if any. file A 1,kolkata,19,ab 2,delhi,89,cd 3,bangalore,56,ef file2: 1,kolkata,21,ab 2,mumbai,89,gh 3,bangalore,11,kl... (9 Replies)
Discussion started by: prabhat.diwaker
9 Replies

3. UNIX for Dummies Questions & Answers

Trim file using filename

I want to remove first xx letters from filename_xx . How is that possible using linux. I have many files where xx could be same in many but filename is always unique. Thanks! (1 Reply)
Discussion started by: keysoon
1 Replies

4. Shell Programming and Scripting

right trim at end of file

Hi, I'have a file as below I need to replace the comma at the end of the file into ) as below Thanks (0 Replies)
Discussion started by: dvah
0 Replies

5. Shell Programming and Scripting

Parse a File ColumnWise & Delete the Rows

Hi , I have a CSV file that has around 50K records in it. I have to delete all the duplicate rows from the file except one, depending upon data in column4. Lets say there are 3 rows for 'column4data' in the file. I have to retain only that line which has the smallest date value in column2.... (3 Replies)
Discussion started by: Sheel
3 Replies

6. UNIX for Advanced & Expert Users

Insert records in a file columnwise

Hello everyone!!!!! Need some help on inserting data in a file columnwise. Example: File1: 1|AAA|25|2 5|qqe|20|7 4|wer|31|81 I need to create a second file in which data can be inserted in a columnwise manner i.e. File2: AAA|25|1|2 qqe|20|5|7 wer|31|4|81 The order of columns in... (1 Reply)
Discussion started by: abhijeet1409
1 Replies

7. Shell Programming and Scripting

Insert records in a file columnwise

Hello everyone!!!!! Need some help on inserting data in a file columnwise. Example: File1: 1|AAA|25|2 5|qqe|20|7 4|wer|31|81 I need to create a second file in which data can be inserted in a columnwise manner i.e. File2: AAA|25|1|2 qqe|20|5|7 wer|31|4|81 The order of columns in... (1 Reply)
Discussion started by: abhijeet1409
1 Replies

8. Shell Programming and Scripting

Comparing files columnwise and print the differences in third file

Hello Everybody!!!!!!!!! Request you to help me with the below mentioned issue: I have 2 files say, File 1: a|4|7 b|3|2 c|8|8 d|8|9 File 2: a|4|6 b|2|2 c|8|8 d|9|8 The third file(output file) should have: Data mismatch in row 1 column 3 Data mismatch in row 2 coumn 2 Data... (3 Replies)
Discussion started by: abhijeet1409
3 Replies

9. UNIX for Dummies Questions & Answers

trim file

Hi, I have a 6G log , which is unusual to read and I want to minimize it by removing some part on the upper portion( around 4GB). what should i do? can you please help me? thanks. (1 Reply)
Discussion started by: tungaw2004
1 Replies

10. Shell Programming and Scripting

rearranging the data in file (from columnwise to rowwise)

Hi I have one file which is having data like 10201 10202 10205 10206 10207 10208 10209 10210 10211 10213 10215 10801 10802 11406 11415 11422 11426 11513 11514 11515 11516 11517 11518 11519 11520 11521 11522 11523 11524 11525 11530 11604 11608 11611 11717 11718 11719 11722 11725... (3 Replies)
Discussion started by: reldb
3 Replies
Login or Register to Ask a Question