- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- string manipulation inquiry
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2005 02:59 PM
тАО10-02-2005 02:59 PM
I have a file with the following contents,
...
...
PRODUCT,XXXYYYZZZ_75_HD20
...
...
i have used awk to get the content of the product field (which is XXXYYYZZZ_75_HD20).
export Var=$(awk -F "," '/PRODUCT/ {print $2}' $FILE)
After getting the product content, i have to manipulate the result by truncating the "_HD20"
which is a contant in some devices (others dont have).
I need to write a script in which it has to test if the content of the product has the "_HD20" strings and eventually put the product in a variable and compare it to other file for matching.
Maximum points for all correct answers!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2005 04:11 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2005 04:27 PM
тАО10-02-2005 04:27 PM
Re: string manipulation inquiry
var='PRODUCT,XXXYYYZZZ_75_HD20'
var1=${var##*,}
check=${var1##*_}
if [[ ${check} = "HD20" ]]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2005 04:38 PM
тАО10-02-2005 04:38 PM
Re: string manipulation inquiry
cat yourFile |
awk -f "," '
/PRODUCT/ {
split($2,a,"_");
print $2, a[1] a[2], a[3];
}' |
while read a b c
print $a $b $c
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2005 04:43 PM
тАО10-02-2005 04:43 PM
Re: string manipulation inquiry
var='PRODUCT,XXXYYYZZZ_75_HD20'
var1=${var##*,}
check=${var1##*_} #remove everything from the begining of the line to the last underscore "_". will be HD20 if it is there
rest=${var1%_*) #remove everything from the end of the line up and including the "_". will be XXXYYYZZZ_75
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2005 06:49 PM
тАО10-02-2005 06:49 PM
Re: string manipulation inquiry
export Var=$(awk -F, '/PRODUCT/ { if ( $2 ~ /HD20/ ) { print $2 }}' $FILE)
where,
a) awk splits with ","
b) check's PRODUCT keyword
c) Prints XXXYYYZZZ_75_HD20 when second field contains HD20 keyword
else Var will empty.
You can check like,
if [ "$var" = "" ]
then
# var is empty
else
# var is with XXXYYYZZZ_75_HD20
fi
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2005 06:52 PM
тАО10-02-2005 06:52 PM
Re: string manipulation inquiry
export product=$(perl -ne 'split /,/; print $_[1] if /PRODUCT,.*HD20/' $FILE)
with check code.
hth.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2005 06:55 PM
тАО10-02-2005 06:55 PM
Re: string manipulation inquiry
export Var=$(awk -F, '/PRODUCT,.*HD20/ { print $2; }' $FILE)
Or else you can directly check it as,
if [ $(awk -F, '/PRODUCT,.*HD20/ { print $2; }') = "" ]
do
# Nothing there
else
# There is HD20
fi
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2005 10:22 PM
тАО10-02-2005 10:22 PM
Re: string manipulation inquiry
Curt Larson's first solution is certainly the fastest and "cheapest". It leverages shell builtins and therefore runs the faster than deploying 'awk' or 'perl' for the simple task.
Regards!
...JRF...