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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
regex to remove text before&&after comma chars yomaya Shell Programming and Scripting 3 06-08-2009 06:44 AM
How to remove comma from the last line of the file sandeep_1105 UNIX for Dummies Questions & Answers 5 05-27-2009 01:01 PM
Delete a comma from string MisterKhan Shell Programming and Scripting 6 03-26-2009 03:36 PM
remove unnecessary comma from file sumeet UNIX for Advanced & Expert Users 1 12-31-2008 06:00 PM
Remove whitespaces between comma separated fields from file nitinbjoshi UNIX for Dummies Questions & Answers 2 06-14-2008 09:14 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 3 Weeks Ago
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by Reddy482 View Post
i had String like

UID: ABC345QWE678GFK345SA90, LENGTH 32

when I used awk ' FS[" "], {print $1}' prints

ABC345QWE678GFK345SA90,

how can i getrid of that coma at the end of the string.

Why would you use awk to operate on a string? The shell can manipulate strings without using an external command.

Code:
var=ABC345QWE678GFK345SA90,
newvar=${var%,}
printf "%s\n" "$newvar"
  #2 (permalink)  
Old 3 Weeks Ago
Scrutinizer Scrutinizer is online now
Registered User
  
 

Join Date: Nov 2008
Posts: 718
Agreed but the OP was using awk anyway to transform
Code:
UID:  ABC345QWE678GFK345SA90, LENGTH 32
into
Code:
ABC345QWE678GFK345SA90,
So you would need a bit more than that to eradicate awk, like:
Code:
ts="UID:               ABC345QWE678GFK345SA90, LENGTH 32"
ts=${ts#*:}
echo "${ts%,*}"
  #3 (permalink)  
Old 3 Weeks Ago
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,434
Quote:
Originally Posted by Scrutinizer View Post
Code:
ts="UID:               ABC345QWE678GFK345SA90, LENGTH 32"
ts=${ts#*:}
echo "${ts%,*}"
We can change the expansion order:
Code:
ts="UID:               ABC345QWE678GFK345SA90, LENGTH 32"
ts="${ts%,*}"
echo ${ts#*:}
or using awk
Code:
echo "UID:  ABC345QWE678GFK345SA90, LENGTH 32"|awk '{sub(",","");print $2}'
or sed
Code:
echo "UID:  ABC345QWE678GFK345SA90, LENGTH 32" | sed 's/.* \(.*\),.*/\1/'
  #4 (permalink)  
Old 3 Weeks Ago
Reddy482 Reddy482 is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 16
Thanks for you replies.


I had an executable file name " uid.out" that generates following ouput when i call it from the shell script.
"Home" is the string that i passed as input to the string.

Using Prod Key
Trying to Encrypt: home
UID: 8C42A3DA2A9BFB9D8E89E4FA9C9FE161, length: 32

Now i want to extract the 8C42A3DA2A9BFB9D8E89E4FA9C9FE161 into variable.
what i did was

uid.out "Home" |grep UID >> temp.txt
=$( awk '{FS=" "} {print $2}' temp.txt)
echo "${Ecode}
produces the ouptut 8C42A3DA2A9BFB9D8E89E4FA9C9FE161,
in which I am not able to seperate Coma(,) at the end string.

What am i doing wrong?

thanks in advance.
  #5 (permalink)  
Old 3 Weeks Ago
Scrutinizer Scrutinizer is online now
Registered User
  
 

Join Date: Nov 2008
Posts: 718
Reddy, have you tried any of the solutions? Leaving optimizations of your code aside, there are close to a gazillion solutions to your problem in this thread. If you are having trouble choosing then just pick one.

Last edited by Scrutinizer; 3 Weeks Ago at 12:56 PM..
  #6 (permalink)  
Old 3 Weeks Ago
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 537
Quote:
Originally Posted by Reddy482 View Post
...
What am i doing wrong?
...
You are not paying close attention to the scripts posted here.


Quote:
Originally Posted by Reddy482 View Post
...
I had an executable file name " uid.out" that generates following ouput when i call it from the shell script.
"Home" is the string that i passed as input to the string.

Using Prod Key
Trying to Encrypt: home
UID: 8C42A3DA2A9BFB9D8E89E4FA9C9FE161, length: 32

Now i want to extract the 8C42A3DA2A9BFB9D8E89E4FA9C9FE161 into variable.
what i did was

uid.out "Home" |grep UID >> temp.txt
=$( awk '{FS=" "} {print $2}' temp.txt)
echo "${Ecode}
produces the ouptut 8C42A3DA2A9BFB9D8E89E4FA9C9FE161,
in which I am not able to seperate Coma(,) at the end string.
...
Try one of these:

Code:
uid.out "Home" | awk -F '[ ,]' '/UID/ {print $2}'
or

Code:
uid.out "Home" | awk -F "[ ,]" '/UID/ {print $2}'
or

Code:
uid.out "Home" | awk 'BEGIN{FS="[ ,]"} /UID/ {print $2}'
or

Code:
uid.out "Home" | perl -lne '/^UID: (\w+),/ && print $1'
tyler_durden
  #7 (permalink)  
Old 3 Weeks Ago
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by Reddy482 View Post
I had an executable file name " uid.out" that generates following ouput when i call it from the shell script.
"Home" is the string that i passed as input to the string.

Using Prod Key
Trying to Encrypt: home
UID: 8C42A3DA2A9BFB9D8E89E4FA9C9FE161, length: 32

Now i want to extract the 8C42A3DA2A9BFB9D8E89E4FA9C9FE161 into variable.
what i did was

uid.out "Home" |grep UID >> temp.txt
=$( awk '{FS=" "} {print $2}' temp.txt)
echo "${Ecode}
produces the ouptut 8C42A3DA2A9BFB9D8E89E4FA9C9FE161,
in which I am not able to seperate Coma(,) at the end string.

Code:
uid.out |
{
 read;read             ## discard first two lines
 IFS=' ,' read a b c   ## what you want is stored in $b
 printf "%s\n" "$b"
}
Bits Awarded / Charged to cfajohnson for this Post
Date User Comment Amount
3 Weeks Ago Reddy482 N/A 516
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 07: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