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
Append each line to next previous line in a file sudhakaryadav Shell Programming and Scripting 8 06-01-2009 11:21 AM
Append line that does not contain pipe to it previous line ainuddin Shell Programming and Scripting 11 11-11-2008 10:58 AM
Joining lines in reverse. append line 1 to line 2. dwalley Shell Programming and Scripting 7 08-04-2008 07:11 AM
How to append some strings line by line? xinoo Shell Programming and Scripting 4 06-24-2008 02:04 AM
append a line to the last line in a file subhrap.das UNIX Desktop for Dummies Questions & Answers 5 04-25-2007 09:17 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
use either nawk or /usr/xpg4/bin/awk if on Solaris
  #2 (permalink)  
Old 4 Weeks Ago
kshuser kshuser is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 30
Quote:
Originally Posted by vgersh99 View Post
use either nawk or /usr/xpg4/bin/awk if on Solaris
thanks it works..

I also like to know i am getting some value into a variable using grep command
Code:
count_trlr=`grep "^3" $DATADIR/$FILE1.DAT| cut -c2-8`
After i get the value into variable i want to remove zeroes
eg: count_trlr=000004 but i want only the number 4 not zeroes like this, count_trlr=4

Code:
 
eg:
contr_trlr=0023343, i want 23343
contr_trlr=1111111, i want 1111111
contr_trlr=0222222, i want only 222222
how to do this in ksh script.

thanks in adv.
  #3 (permalink)  
Old 4 Weeks Ago
SFNYC SFNYC is offline
Registered User
  
 

Join Date: Jun 2008
Location: New York City
Posts: 95
Code:
$ contr_trlr=0023343
$ echo  $contr_trlr|tr -d '^0'
23343

$ contr_trlr=1111111
$ echo  $contr_trlr|tr -d '^0'
1111111

$ contr_trlr=0222222
$ echo  $contr_trlr|tr -d '^0'
222222
  #4 (permalink)  
Old 4 Weeks Ago
SFNYC SFNYC is offline
Registered User
  
 

Join Date: Jun 2008
Location: New York City
Posts: 95
Code:
$ cat FILE1.TXT
2293847982374 sdj 23423
2298372038974 dsj 23492
2972837629376 abj 34929
2984836398384 abc 39723

$ cat ./add_trailer.ksh
#!/bin/ksh
MYFILE=FILE1.TXT
FILECOUNT=$(wc -l < $MYFILE 2>/dev/null)
typeset -Z6 TRAILER=${FILECOUNT:-0}
echo "3$TRAILER" >> $MYFILE
exit 0

$ ./add_trailer.ksh

$ cat FILE1.TXT
2293847982374 sdj 23423
2298372038974 dsj 23492
2972837629376 abj 34929
2984836398384 abc 39723
3000004
  #5 (permalink)  
Old 4 Weeks Ago
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Code:
#!/bin/ksh

typeset -i count_trlr=$(grep "^3" $DATADIR/$FILE1.DAT| cut -c2-8)
Reply

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 05:17 PM.


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