The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-08-2008
ust ust is offline
Registered User
 

Join Date: Feb 2005
Posts: 95
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 ?
Reply With Quote
Forum Sponsor
  #2  
Old 01-08-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
Code:
echo 'aaa;20071217' | sed 's/.*\(....\)/\1/'
Reply With Quote
  #3  
Old 01-08-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,329
Quote:
Originally Posted by ust View Post
if I want to cut the column 9-12
Simply:

Code:
cut -c 9-12
or:

Code:
awk '{print substr($0, 9, 4)}'
Regards
Reply With Quote
  #4  
Old 01-08-2008
Registered User
 

Join Date: Oct 2007
Posts: 70
<prompt>$ cut -b 9- myfile > cutfile
<prompt>$ cat cutfile
or
<prompt>$ cat myfile | cut -b 9-
Reply With Quote
  #5  
Old 01-08-2008
ust ust is offline
Registered User
 

Join Date: Feb 2005
Posts: 95
Quote:
Originally Posted by Franklin52 View Post
Simply:

Code:
cut -c 9-12
or:

Code:
awk '{print substr($0, 9, 4)}'
Regards
thx reply ,

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
Reply With Quote
  #6  
Old 01-09-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,329
Code:
awk 'NR==1{print substr($0, 9, 4);exit}'
Regards
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0