search all file for particular text and make changes to line 3


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers search all file for particular text and make changes to line 3
# 8  
Old 06-24-2011
You are dead right on this. there is no point repeating the same codes in many files, this will sometime takes the system down to it's knee. well , I was also planning for that paramatrized script, but , since I still new to shell arena. I did bit learn bit of shell scripting and able to create some sort of script, that does the purpose in our envoiornment. You people are great help, during the creation of script. I am workiing hard to learn it, I know this is no rocket science. however, I still have some question from my existing script. I would appriciate, if you could elaborate on following lines.
does this time format looks ok to you?
Code:
typeset -i mHHMM=`date +%H%M`
typeset -i mDD=$(date +%d)
mDay=`date +%a`
if [[ "${mDay}" = "Sun" && ${mHHMM} -gt 0150 ]]; then

hare krishna
# 9  
Old 06-24-2011
Do you no longer want that line you were asking about modified, then? I still don't have enough information to give you an answer about it.

Code:
typeset -i mHHMM=`date +%H%M`

You don't need to "typeset -i", all this does is force it to evaluate a number earlier.

Numbers with leading zeroes will be interpreted as octal. This could have unforseen effects in your math. Things with digits above 7 won't work at all:

Code:
$ typeset -i val=0159
-bash: typeset: 0159: value too great for base (error token is "0159")

So you should get the strings and strip off the leading zeroes before trying to compare them; or just compare them as strings. How to do this depends on your shell and system, what is it?
This User Gave Thanks to Corona688 For This Post:
# 10  
Old 06-25-2011
Thanks Corona for this. You've always been a great help for me. I think, I need to take away the leading "zeros" from my script. thanks a lot, once again


hare krishna
Smilie
# 11  
Old 06-30-2011
Sorry for not getting back to this.

Still need an answer to this:
Quote:
Originally Posted by Corona688
Do you no longer want that line you were asking about modified, then? I still don't have enough information to give you an answer about it.
As for removing leading zeroes, I still need an answer to this:
Quote:
Originally Posted by Corona688
How to do this depends on your shell and system, what is it?
But if you have BASH or a recent KSH, you can do:

Code:
while [ "${STR:0:1}" = "0" ] ; do STR="${STR:1}" ; done

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search a string and display its location on the entire string and make a text file

I want to search a small string in a large string and find the locations of the string. For this I used grep "string" -ob <file name where the large string is stored>. Now this gives me the locations of that string. Now how do I store these locations in a text file. Please use CODE tags as... (7 Replies)
Discussion started by: ANKIT ROY
7 Replies

2. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

3. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

4. Shell Programming and Scripting

Search a string in a text file and add another string at the particular position of a line

I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies

5. Shell Programming and Scripting

search between keywords and make a single line

have a very big file where need to format it like below example file: abcd today is great day; search keyword 'abcd' and append to it all words till we reach ; to make it a single line. output should look like. abcd today is great day; There are many occurrence of such... (2 Replies)
Discussion started by: giri4332
2 Replies

6. Shell Programming and Scripting

PERL or SHELL Scrript to search in Directories by taking line by line from a text file

Unix box server version *********** >uname -r B.11.00 >echo $SHELL /usr/bin/ksh --> in this server, I have the path like /IMbuild/dev/im0serv1 ---> in that directory I have the folders startup(.jsp files nearly 100 jsp's ) and scripts(contains .js files nearly 100 files) ... (9 Replies)
Discussion started by: pasam
9 Replies

7. Shell Programming and Scripting

Search text from a file and print text and one previous line too

Hi, Please let me know how to find text and print text and its previous line. Please don't get irritated few days back I asked text and next line. I am using HP-UX 11.11 Thanks for your help. (6 Replies)
Discussion started by: kamranjalal
6 Replies

8. Shell Programming and Scripting

reverse search a text file from a specified line

Hello All, I have a following task that I need to accomplish through a script or program and I am looking for some help as I have exhausted my ideas. 1. given: a text file with thousands of lines 2. find: pattern A in file and get line number ( grep -n works) 3. find: the first occurence of... (14 Replies)
Discussion started by: PacificWonder
14 Replies

9. UNIX for Dummies Questions & Answers

how can search a String in one text file and replace the whole line in another file

i am very new to UNIX plz help me in this scenario i have two text files as below file1.txt name=Rajakumar. Discipline=Electronics and communication. Designation=software Engineer. file2.txt name=Kannan. Discipline=Mechanical. Designation=CADD Design Engineer. ... (6 Replies)
Discussion started by: kkraja
6 Replies

10. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies
Login or Register to Ask a Question