Little formatting help needed.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Little formatting help needed.
# 1  
Old 03-23-2010
Little formatting help needed.

I have a following string.

"machine=IFLMUD5HP0581&group1=Stop"

I have created 2 variables namely machine and action.

machine should contain
IFLMUD5HP0581
action should contain
Stop

How do i write a script for the same.
# 2  
Old 03-23-2010
amit@softpc142108 ars $ echo "machine=IFLMUD5HP0581&group1=Stop" | cut -d '=' -f2 |cut -d '&' -f1
IFLMUD5HP0581
amit@softpc142108 ars $ echo "machine=IFLMUD5HP0581&group1=Stop" | cut -d '=' -f3
Stop
# 3  
Old 03-23-2010
Code:
 echo "machine=IFLMUD5HP0581&group1=Stop"|sed 's/.*=\(.[^=]*\)\(.*\)\(&.[^=]*\)=\(.[^=]*\)/\1 \4/'

Code:
 echo "machine=IFLMUD5HP0581&group1=Stop"|sed 's/.[^=]*=//;s/&.[^=]*=/ /'

# 4  
Old 03-23-2010
use eval :
Code:
STRING="machine=IFLMUD5HP0581&group1=Stop"
eval ${STRING#*&}
eval ${STRING%&*}
echo "machine = $machine - group1 = $group1"

# 5  
Old 03-23-2010
Try this:

Code:
echo "machine=IFLMUD5HP0581&group1=Stop" |awk -F"[=&]" '{ print $2,$4}' | read machine action

echo $machine
echo $action

# 6  
Old 03-23-2010
Thank you very much for all of your support.
# 7  
Old 03-23-2010
Code:
awk -F '=' '{ print $2 " "$3}' filename | awk -F '&' '{ print $1}'

Code:
awk -F '=' '{ print $2 " "$3}' filename | awk '{ print $2}'


Last edited by pludi; 03-23-2010 at 08:41 AM.. Reason: code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help needed in formatting the output

Hi All, Need your help in resolving the below issue. I've a file called "data.txt" with the below lines: TT: <tell://me/sreenivas> <tell://me/100> <tell://me/500> TT: <tell://me/sudheer> <tell://me/300> TT: <tell://me/sreenivas> <tell://me/200> TT:... (6 Replies)
Discussion started by: raosr020
6 Replies

2. Shell Programming and Scripting

Help needed in formatting the Output file

Hi All, Need your help in resolving the below issue. I've a file called "data.txt" with the below lines: TT: <tell://me/sreenivas> <tell://me/100> TT: <tell://me/sudheer> <tell://me/300> TT: <tell://me/sreenivas> <tell://me/200> TT: <tell://me/sudheer> <tell://me/400> ... (3 Replies)
Discussion started by: raosr020
3 Replies

3. Shell Programming and Scripting

formatting of df -k

Hello, I am developing a platform Independant tool that should work for all major unix flavors outlined in this forum(Solaris,Linux, AIX, HPUX, SCO,BSD) Therefore, in order to cover all types of user community, I have deliberately posted the same message on every forum. Please do not think... (9 Replies)
Discussion started by: darsh123
9 Replies

4. Shell Programming and Scripting

Formatting

Is there a way to make a 2 column output out of the following : 1 2 3 4 5 6 Output : 1 2 3 4 5 6 Thanks, Prasanna (3 Replies)
Discussion started by: prasanna1157
3 Replies

5. Shell Programming and Scripting

Help needed in formatting script files

Hi, Can anyone tell me how i can convert all tab spaces inside a script to 4 spaces through another script. Also i need to find if all the quotes are matching and ended properly. Any idea whould be of great help. Many thanks! (3 Replies)
Discussion started by: justchill
3 Replies

6. Shell Programming and Scripting

Formatting help needed awk or sed maybe

I am executing the following command: sort file1.txt | uniq -c | sort -n > file2.txt The problem is that in file 2, I get leading spaces, Like so: 1 N/A|A8MW11 8 N/A|ufwo1 9 N/A|a8mw11 10 900003|smoketest297688 10 N/A|a9dg4 10 danny|danni 12... (5 Replies)
Discussion started by: ddurden7
5 Replies

7. UNIX for Dummies Questions & Answers

Formatting Help needed

How would i write a script which will add a following content to a file. File Before running script. acpi = 1 apic = 1 builder = 'hvm' device_model = '/usr/lib/xen/bin/qemu-dm' disk = File After running the script. acpi = 1 apic = 1 builder = 'hvm' device_model =... (5 Replies)
Discussion started by: pinga123
5 Replies

8. Shell Programming and Scripting

Formatting Help needed(Sed)

I have a file called abc.txt which has following contents. 10.180.8.231=31608 10.180.8.232=29011 10.180.8.233=31606 10.180.8.234=40501 10.180.8.235=32591 10.180.8.236=31605 10.180.8.237=30561 10.180.8.238=14231 How would i find a ip address having maximum number of ram available. Here... (2 Replies)
Discussion started by: pinga123
2 Replies

9. Shell Programming and Scripting

Output formatting help needed.

Hi guys , I have a file which contains following string.(filename tempdisplay) (location 0.0.0.0:5900) i needed to write a script which will extract the string that comes after 0.0.0.0 i.e the string :5900. I have used following method to extract the string :5900 .Is it a preferred way of... (4 Replies)
Discussion started by: pinga123
4 Replies

10. Shell Programming and Scripting

formatting

I have file with different columns for ex. contents of file "txt" NAME AGE MARKS HARRY 23 89 TOM 12 67 BOB 23 11 and you see its not formatted.Now, I need the file "txt" to be formatted like COLUMN1 COLUMN2 COLUMN3 NAME AGE ... (3 Replies)
Discussion started by: vijay_0209
3 Replies
Login or Register to Ask a Question