![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to read the column and print the values under that column | gemini106 | Shell Programming and Scripting | 6 | 03-28-2008 04:05 AM |
| How to check Null values in a file column by column if columns are Not NULLs | Mandab | Shell Programming and Scripting | 7 | 03-15-2008 06:57 AM |
| extracting/copy a column into a new column | folashandy | UNIX for Advanced & Expert Users | 1 | 02-21-2008 10:24 AM |
| How to pass one parameter from one column to another column in AWK | prasanta jena | Shell Programming and Scripting | 1 | 07-30-2007 03:08 AM |
| Replace 10th column with a new column--- Terriblly hurry | ahmedwaseem2000 | Shell Programming and Scripting | 2 | 09-05-2005 10:10 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
cut column
I have a file as below,
$vi myfile aaa;20071217 bbb;20070404 ccc;20070254 " if I want to cut the column 9-12 of the first line , the output should be 1217 , can advise how to write a script to get the result ? thx p.s. can a script that have only ONE line could do that ? |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
echo 'aaa;20071217' | sed 's/.*\(....\)/\1/' |
|
#3
|
|||
|
|||
|
Simply:
Code:
cut -c 9-12 Code:
awk '{print substr($0, 9, 4)}'
|
|
#4
|
|||
|
|||
|
<prompt>$ cut -b 9- myfile > cutfile
<prompt>$ cat cutfile or <prompt>$ cat myfile | cut -b 9- |
|
#5
|
|||
|
|||
|
Quote:
I tried it , the result is as below, 1217 0404 0254 if I only want the get the date in FIRST line , the result is 1217 , can advise how to modify the script ? thx |
|
#6
|
|||
|
|||
|
Code:
awk 'NR==1{print substr($0, 9, 4);exit}'
|
|||
| Google The UNIX and Linux Forums |