![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Converting Column to Rows in a Flat file | srinikal | Shell Programming and Scripting | 5 | 10-10-2008 04:32 PM |
| Flat file manipulation, (this could be a tough one) | mrbungle50 | Shell Programming and Scripting | 2 | 01-10-2008 04:46 AM |
| Look up column in a flat file | jambesh | Shell Programming and Scripting | 5 | 09-18-2006 06:44 AM |
| Column names in flat files | srivsn | Shell Programming and Scripting | 1 | 12-27-2005 06:47 AM |
| File Manipulation (Move Column Position) | ultimate | Shell Programming and Scripting | 1 | 03-29-2005 11:22 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Flat File column manipulation
Hi All,
I have a tab delimited input file with say 4 fields (columns) as below : 0000443 1AGPR061 2006 Daiml 0002198 1B3XG0K2 1989 Chdds 0002199 1Bd64J0L 1990 Ch34s 0002275 1B3s4J0K 1989 Chadys 0002276 1B465302 2002 Dageml 0002290 1B45430K 1989 Cays I want the 2nd column in file to be replaced with only first 2 chars and 6th char of the 2nd column values, so output should look like : 0000443 1A0 2006 Daiml 0002198 1B0 1989 Chdds 0002199 1BJ 1990 Ch34s 0002275 1BJ 1989 Chadys 0002276 1B3 2002 Dageml 0002290 1B3 1989 Cays Can anyone help me with this ? |
|
||||
|
Code:
cat temp.txt | perl -T\t -ane '$F[1] =~ s/^(.{2}).{3}(.).*$/$1$2/; print join("\t", @F) . "\n"'
The -T flag tells Perl to split the string into an array. In this case, by tabs. Then you do a regex on the second element of the array, then re-join them with tabs. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|