|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Search this Thread |
|
#1
|
|||
|
|||
|
Remove SPACES between PIPE delimited file
This is my input file with extra information in the HEADER and leading & trailing SPACES between PIPE delimiter.
02/04/2010 Dynamic List Display 1 -------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------- | FIST_NAME|LAST_NAME|ADDRESS | -------------------------------------------------------------------------------------- | Rajesh |Verma |10/27/2004| | James |David Jr |10/08/2009| -------------------------------------------------------------------------------------- How to make output file like this, please help with UNIX script FIST_NAME|LAST_NAME|ADDRESS| Rajesh|Verma|164 N Tutor Ln, Chicago-IL| James|David Jr|529 Carlton Arms Dr, Chicago-IL| Thanks srimitta |
| Sponsored Links | ||
|
|
|
#2
|
|||
|
|||
|
it's funny
02/04/2010 Dynamic List Display 1 -------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------- | FIST_NAME|LAST_NAME|ADDRESS | -------------------------------------------------------------------------------------- | Rajesh |Verma |10/27/2004| | James |David Jr |10/08/2009| -------------------------------------------------------------------------------------- How to make output file like this, please help with UNIX script FIST_NAME|LAST_NAME|ADDRESS| Rajesh|Verma|164 N Tutor Ln, Chicago-IL| James|David Jr|529 Carlton Arms Dr, Chicago-IL| What's from the address??? Last edited by john1212; 03-13-2010 at 04:13 PM.. |
|
#3
|
|||
|
|||
|
Code:
awk -F\| '{for(i=1;i<=NF;i++) gsub("^[ \t]*|[ \t]*$","",$i)}1' OFS=\| FILELast edited by EAGL€; 03-13-2010 at 05:57 PM.. Reason: changed delimeter from "#" to "|" |
|
#4
|
|||
|
|||
|
Hi, srimitta: Code:
$ cat data
02/04/2010 Dynamic List Display 1
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
| FIST_NAME|LAST_NAME|ADDRESS |
--------------------------------------------------------------------------------------
| Rajesh |Verma |10/27/2004|
| James |David Jr |10/08/2009|
--------------------------------------------------------------------------------------
$ sed -n '/^| */{s///;s/ *| */|/g;p;}' data
FIST_NAME|LAST_NAME|ADDRESS|
Rajesh|Verma|10/27/2004|
James|David Jr|10/08/2009|Regards, Alister |
|
#5
|
|||
|
|||
|
john1212, Address was copy / paste mistake.
Thanks Alister worked like charm. Quote:
Regards srimitta |
|
#6
|
||||
|
||||
|
Using Perl: Code:
$ $ cat f0 02/04/2010 Dynamic List Display 1 -------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------- | FIST_NAME|LAST_NAME|ADDRESS | -------------------------------------------------------------------------------------- | Rajesh |Verma |10/27/2004| | James |David Jr |10/08/2009| -------------------------------------------------------------------------------------- $ $ perl -lne 's/\s*\|\s*/\|/g && print' f0 |FIST_NAME|LAST_NAME|ADDRESS| |Rajesh|Verma|10/27/2004| |James|David Jr|10/08/2009| $ $ tyler_durden |
|
#7
|
||||
|
||||
|
Quote:
Another straight awk solution. Code:
awk -F"|" '/^\|/ { OFS="\|"; gsub(/ /,"",$0); print $2,$3,$4,$5; }' file |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Delete last value from pipe delimited file | relentl3ss | UNIX for Dummies Questions & Answers | 3 | 02-17-2010 05:27 AM |
| convert a pipe delimited file to a':" delimited file | priyanka3006 | Shell Programming and Scripting | 6 | 05-26-2009 10:53 AM |
| Extracting from pipe delimited file. | leepan2008 | UNIX for Dummies Questions & Answers | 1 | 02-17-2009 02:55 AM |
| How to generate a pipe ( | ) delimited file? | anushree.a | Shell Programming and Scripting | 5 | 10-15-2008 02:35 AM |
| How to split pipe delimited file | njgirl | Shell Programming and Scripting | 4 | 06-18-2008 05:15 PM |