Need help with a string manupilation in Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with a string manupilation in Shell Script
# 8  
Old 06-25-2009
Quote:
Originally Posted by bubbly
The file has mutiple lines which needs to be parsed to get the out put as desired

The question is. "How many lines?"

If it is less than 20, the script I posted will be faster. If it's more than 100, awk or sed will be faster.
# 9  
Old 06-25-2009
Hi vgersh99,


Thank you for the reply. The command works fine to get the out put as

[GRANT select ON *.*] ['atlrep'@'10.8.5.%']

Can you please help me the same command as two induvidual commands to get the output directed to 2 new files. Where i need to further parse them.


Thanks
# 10  
Old 06-26-2009
Code:
nawk -F' TO ' '{print  $1 > "file1" ; print substr($2,1, index($2, " ")-1) > "file2" }' myFile

# 11  
Old 06-26-2009
Hi


Thank you all for the reply. In addition can you please let me know how to cut the first word of every line in a text file. There are more then 20 lines in the file.

Thanks
# 12  
Old 06-26-2009
Quote:
Originally Posted by bubbly
Hi


Thank you all for the reply. In addition can you please let me know how to cut the first word of every line in a text file. There are more then 20 lines in the file.

Thanks
depends on what you mean by 'cut' and by 'word'..
Code:
sed 's/^\([^ ][^ ]*\).*/\1/' myFile
OR
awk '{print $1}' myFile

# 13  
Old 06-26-2009
Hi vgersh99,


Thank you for the reply. I was looking at remove the word grant from the above output in the first command ..for eg

File 1
[GRANT select ON *.*]

remove the word GRANT out of the above line. so can we use sed with awk which you gave initially

awk -F' TO ' '{print $1 **sed** > "file1" ; print substr($2,1, index($2, " ")-1) > "file2" }' grantfiles.

In short, i want the out put like

GRANT SELECT ON `ods`.* TO 'systemsDBuser'@'%';

[SELECT ] ON [`ods`.*] TO ['systemsDBuser'@'%'];

while the [] values in 3 different files.

Thanks
# 14  
Old 06-26-2009
Code:
nawk -F' TO ' '{sp=index($1, " ");print  substr($1,1,sp-1) > "file1"; substr($1,sp+1) > "file2" ; print substr($2,1, index($2, " ")-1) > "file3" }' myFile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

-a String operator in shell script

What does -a operator for String manipulation imply? Eg: if ;then (2 Replies)
Discussion started by: Sree10
2 Replies

2. Shell Programming and Scripting

String validation in shell script

Hi All, I am a newbie...I would like to have a function which ll check if a file contains valid strings before "=" operator. Just to give you my requirement: assume my file has content: hello= gsdgsd sfdsg sgdsg sgdgdg world= gggg hhhh iiiii xxxx= pppp ppppp pppp my... (1 Reply)
Discussion started by: rtagarra
1 Replies

3. Shell Programming and Scripting

How to get the last value from a string in shell script?

I have to get the last value from a string, below is the example string String -> Here is the test string 12233 O/P -> 12233 String -> Hello world 500 O/P -> 500 String -> 300 O/P -> 300 Please help (2 Replies)
Discussion started by: vel4ever
2 Replies

4. UNIX for Dummies Questions & Answers

Comparing a String variable with a string literal in a Debian shell script

Hi All, I am trying to to compare a string variable with a string literal inside a loop but keep getting the ./testifstructure.sh: line 6: #!/bin/sh BOOK_LIST="BOOK1 BOOK2" for BOOK in ${BOOK_LIST} do if then echo '1' else echo '2' fi done Please use next... (1 Reply)
Discussion started by: daveu7
1 Replies

5. Shell Programming and Scripting

operating on string in shell script

i want to read a string and reverse it. hoe do i do that..?? (1 Reply)
Discussion started by: akshaykumar6
1 Replies

6. Shell Programming and Scripting

TRIM a string in shell script

HI, I have a string "NZ-deploy-mode-1.15-Linux.x86_64.rpm" I want to get the string before -1 ie "NZ-deploy-mode" Input is "NZ-deploy-mode-1.15-Linux.x86_64.rpm" expected output is "NZ-deploy-mode" How can I do that in shell script? Thanks in advance. (6 Replies)
Discussion started by: Ananthdoss
6 Replies

7. Shell Programming and Scripting

Manipulate string in shell script

I am writing a shell script for some purpose. I have a variable of the form -- var1 = "policy=set policy" Now I need to manipulate the variable var to get the string after index =. that is i should have "set polcy". Also I need to to this for many other variables where the value of "=" is not... (3 Replies)
Discussion started by: Dev_Sharma987
3 Replies

8. Shell Programming and Scripting

Shell script for encrypting a string

Hi, I am new to Unix server and shell scripting.I want to encrypt username/password using shell script.I know that there's a Crypt command to encrypt but it is not installed in my unix server and cannot be installed due to some reason.So i want the shell script of the crypt command or is there... (3 Replies)
Discussion started by: Princessp
3 Replies

9. Shell Programming and Scripting

How to build a string in shell script

Hi all, I had a typical problem. I am using a parameter PK="PK1 PK2 PK3" i need to build the string a.PK1=b.PK1 and a.PK2=b.PK2 and a.PK3=b.PK3 Please help (8 Replies)
Discussion started by: nkosaraju
8 Replies

10. Shell Programming and Scripting

shell script string extension

hey, im looking for a way of extending a string in shell script. for example i have two strings "." and "abcd", i need to extend the first string so that it is the same length as the second. so "." and "abcd" becomes "...." and "abcd", could someone shed light on how to do this ? thanks (4 Replies)
Discussion started by: vbm
4 Replies
Login or Register to Ask a Question