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
Substr in shell script gjithin Shell Programming and Scripting 7 05-10-2008 01:40 PM
Help with Korn Shell script heprox AIX 1 12-19-2005 10:04 AM
korn shell script pavan_test UNIX Desktop for Dummies Questions & Answers 3 10-27-2005 09:09 AM
korn shell script pavan_test UNIX for Dummies Questions & Answers 1 10-26-2005 10:17 AM
Trouble using substr function with Bourne shell script E2004 Shell Programming and Scripting 4 09-29-2005 07:57 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-23-2008
Registered User
 

Join Date: Jan 2008
Posts: 5
substr() thru awk Korn Shell Script

Hi,

I am new stuff to learn substr() function through awk for writing the Korn shell script.

Is there a way to copy from XXXX1234.ABCDEF to XXX1234 file names without changing both data files?

I appreciate your time to response this email.

Thanks,
Steve
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-23-2008
Registered User
 

Join Date: Jan 2008
Posts: 6
I don't understand your question

Are you copying a file named "XXXX1234.ABCDEF" to "XXX1234"? (#1)

Or are you transforming one file to another and transforming the contents from "XXXX1234.ABCDEF" to "XXX1234"? (#2)

And did you mean to have 4 X's in the first and 3 in the second?

If #2 above, must you use korn/awk? Any of python/ruby/perl/sed would do the job as well.
--
Qman
Reply With Quote
  #3 (permalink)  
Old 01-24-2008
Registered User
 

Join Date: Jan 2008
Posts: 5
substr() thru awk Korn Shell Script

Hi qneill,

Thanks for your time to review my post.

I knew I am not clear myself because I am not a techie person.

This morning, I reviewed the Similar Thread section and found a solution to separate the file name fields using the awk command.
For example, a file named “XXXX.12345.YYYY” must be changed to “XXXX.12345”.
The echo result of the command line as echo “XXXX.12345.YYYY” | `awk –F. ‘{print $1}’` is “XXXX”. However, I need to use the same command line above for combining the first two fields of the file named “XXXX.12345” Is there a way to show the results of the first two fields of the file name?

Thanks,
sbryant
Reply With Quote
  #4 (permalink)  
Old 01-24-2008
Moderator
 

Join Date: Dec 2003
Location: /ksh93
Posts: 849
Code:
echo "XXXX.12345.YYYY" | awk -F. '{print $1"."$2}'
or

Code:
echo "XXXX.12345.YYYY" | awk -F. '{printf("%s.%s", $1, $2)}'
Reply With Quote
  #5 (permalink)  
Old 01-24-2008
Registered User
 

Join Date: Jan 2008
Posts: 5
substr() thru awk Korn Shell Script

Perfect! Thanks for your time and help.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:01 PM.


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

Content Relevant URLs by vBSEO 3.2.0