The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-23-2008
sbryant sbryant is offline
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
  #2 (permalink)  
Old 01-23-2008
qneill qneill is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 23
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
  #3 (permalink)  
Old 01-24-2008
sbryant sbryant is offline
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
  #4 (permalink)  
Old 01-24-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

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

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

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

Perfect! Thanks for your time and help.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0