Programming :: Find String In Text File (bash Script)

Apr 17, 2011

write such script (bash script). I have some text file with name filename.txt I must check if this file contains string "test-string-first", I must cut from this file string which follows string "keyword-string:" and till first white-space and save it to some variable.

For example. File: PHP Code: PHP Code:
Start 15022011 Eng 12-3-42
SN1232324422 11 test-string-first
SN322211 securities
HH keyword-string:123456321-net mark (11-22) 

[Code].....

View 1 Replies


ADVERTISEMENT

Programming :: Find String In Text File And Add Something To That Line

May 26, 2011

I want to know how can I add something to a specific line.. the output would be something like:
abc
def 123
ghi

Search for string "def" and add something to that line.

View 1 Replies View Related

Programming :: Find And Replace A String In A File Using Perl Command From Bash Script?

Feb 14, 2011

I wanted to find and replace a string from a perl file. I have written a script in bash which runs the following command.

perl -pi -e "s/$findstring/$replacestring/" testfile
where as $findstring = print F_WC_TMP"$line
";
and $replaceString = $line = join ' ', split ' ', $line; print F_WC_TMP"$line
";

But when I am running the above command, i think it is replacing the $findstring with the above mentioned string and hence it contains a $line, it is looking for the variable $line and not finding the exact string. I am confused about how to search for a string that contains $ in it and replace it with another $string.

View 5 Replies View Related

General :: Find Text After String Search In File

Aug 2, 2011

I have a file called Regions.ini that looks like this:

Code:
[Granite]
RegionUUID = 54ab7cd2-0e70-49b7-8020-8dbeb84c08d0
Location = 9991,10007
InternalAddress = 0.0.0.0
InternalPort = 9001
AllowAlternatePorts = False
ExternalHostName = 71.171.21.9

[Syenite]
RegionUUID = 8fc56fdd-0afd-4074-9432-0ae8f42b799f
Location = 9992,10007
InternalAddress = 0.0.0.0
InternalPort = 9000
AllowAlternatePorts = False
ExternalHostName = 71.171.21.9
What I need to do is find out what the IP address is after "ExternalHostName ="

After that I will need to compare that IP to whatismyip and if it's different then replace it but that is easy to do with sed. I just can't figure this simple hurdle out.

View 12 Replies View Related

Programming :: Find A Substring/member In A String/array Using Bash?

Oct 13, 2010

This may be a basic bash array/string operation related question, but I couldn't find any direct answer. So here it goes:I have a lot of data sorted in various directories. All directories need same processing except for a special group of directories. I have a symbolic link of the script in discussion in each directory. I want the script to get the name of the current directory, check if that belongs to special group and do specific operations.So I get the name of the directory

Code:
mm=`basename `pwd``
Now the the group of directories that needs something different to be done, contains these

[code]...

View 4 Replies View Related

Programming :: String Format - Create A Text File ?

Feb 3, 2010

I am using C. I have a fuction that returns a string

Code:

I need to format this string so that I can create a text file like so:

So I'm trying:

Code:

But I get errors like:

View 2 Replies View Related

Programming :: String Search In Text File Using Visual C++

Jan 25, 2010

im tryin to make a tool in visual C++ which will take an input string through a text box,then it will compare tht string with a text file containing data and display the matched results in list box.

View 2 Replies View Related

Programming :: Bash Removing String From File?

Aug 7, 2010

I am trying to remove everything before my string code...

View 9 Replies View Related

Debian Programming :: Script To Execute String From Text File

Sep 24, 2014

I am having trouble writing a script that monitors a text file. When the file contains number 1 (or any other string that is not a command) it does nothing, but when it is something different from 1, it executes that command.

So, there are 2 files: monitor.mon - this is the file that will be checked constanlty; and test.sh - the script that does the job. The monitor.mon file will have its content modified by php. This means a web page will have a form where I input commands and writes does commands in the file. Test.sh will watch when the file's content changes from character 1 to a command, execute that command and write back a 1 so it will not execute it more times.

I tried combining while and if but with no success. Tried reading the file with cat and grep -e but it doesn't seem to recognize when content changes.

View 4 Replies View Related

Programming :: Text File Replace Occurrences Of Three Character String ZZZ With Quotation Mark

Mar 30, 2010

I want to use SED to do the following: In a text file replace any occurrences of the three character string ZZZ with a quotation mark "and. replace all occurrences of a comma with a semi-colon. It is the S/ / / command which is stumping me on the first issue...inparticular how to get the replace string to be quote.

View 9 Replies View Related

Programming :: Perl Find File And Then Replace String In File

Jul 28, 2009

I have script that I'm working on that updates a username in all the files that are called blah.inc for my framework. since i host a bunch of these web apps i need to do it to all of them. so I need to figure out how to update these files automagically with out me watching it to call vim every time. heres what I have so far

Code:

This finds the files but now i need to figure out how to do s/bob/fred/g on those files.

View 5 Replies View Related

Programming :: Find A String In A File Without Using Grep?

Oct 27, 2010

I want to write some code to search for a specific string in a text file, but without using grep command.

View 5 Replies View Related

Programming :: Reading In A Outside Text File And Putting In The String On That Line Into A Char Array That Is Already Allocated?

Mar 29, 2011

Here is the issue. I am reading in a outside text file and putting in the string on that line into a char array that is already allocated.

Code:
int main(int argc, char *argv[])
{

[code]....

View 1 Replies View Related

Ubuntu :: Bash Command To Find And Replace Text In File

Apr 3, 2010

I'm having problems with Tomboy. I have a few hundred note files and I need to go through all of them and replace all instances of "<link:broken>a</link:broken>" with "a". Is there a bash command I can use to do this?

View 2 Replies View Related

Software :: Replace A Text String In A File With A Random String - With Sed ?

Sep 2, 2010

I have a line in a text file that has 40 random characters within a tag and i want to change the characters to a new set of 40 random characters (alphanumeric a-z 0-9 etc)

The line in the text file looks like this:

Quote:

How would i go about doing that?

Also second question same as the above but how would i remove them instead of replacing them?

View 14 Replies View Related

Programming :: Reading From Text File In Bash?

Nov 8, 2010

I need to Read a path of a file witch is written in Text file i used this

Code:

FILENAME=$1
while read line
do
echo $line
done < $FILENAME

it worked and showed me the Line witch was written in my file but now my problem is how am gonna use that line as a path i mean for example if am gonna execute a linux command on that file like dpkg -i /path/to/the/file how am gonna export it from The $Line variable and use it after the command.

View 14 Replies View Related

Fedora :: Replace A String By A String In Text File?

Apr 26, 2011

If I have a word in a text file and I need to replace it by another word (for example, i need to replace abc by fff) so what is the command I can type it?

I am using vi editor.

View 3 Replies View Related

Programming :: Bash: Split A Text File Into An Array?

Sep 18, 2010

I have a file (called twitterstatus.tmp) that looks like this:

Code:

<status>
<id>24854489768</id>
<text>Are we gonna ride the sun home?</text>
<id>55266987</id>

[code].....

How could I feed this into an array, with each element containing everything between the <status> </status> tags?

View 9 Replies View Related

Programming :: Get The Specific Text From A Txt File In Bash Script?

Apr 30, 2010

I have a text file which stores the list of files & dir, I want to get only file's extensions from this file & want to store it in another file.eg, below is the file's contents & from it I want to get the extensions sh, pl & h & want to store it in another file. Also I don't want directory list.

A scripts/services_restarter.sh
A scripts/svn post_commit scripts
A scripts/tmp/

[code]...

View 8 Replies View Related

Programming :: Write An If Statement For The First Line Of A Text File Bash?

Feb 15, 2011

At the moment I got my md5sum checking working which I write to a text file and see below.

If the md5sum works it will write the output to check2.md5 test.txt: OK

If the md5sum fails it will write test.txt: FAILED

How do I write if statement to check the output whether or not the md5sum failed or not ?

check1="/home/ops/Desktop/test1/check1.md5"
check2="/home/ops/Desktop/test1/check2.md5"
cd /home/ops/Desktop/test1
md5sum test.txt > $check1

[Code]....

View 2 Replies View Related

Programming :: (BASH) How To Read Multiple Lines From Text File

Mar 11, 2011

For example, I have a text file with data which lists numerical values from two separate individuals

Code:
Person A
100
200
300
400
500
600
700
800
900
1000
1100
1200

Person B
1200
1100
1000
900
800
700
600
500
400
300
200
100

How would I go about reading the values for each Person, then being able to perform mathematical equations for each Person (finding the sum for example)?

View 13 Replies View Related

Programming :: Bash: Feeding Input To A Script From A Text File?

Nov 17, 2010

I have a script which checks on my jobs that run on some cluster.The script, "script.sh", takes as an input the job-id for the job to be checked. Sometimes I have 100s of jobs and I want to check them all (for successful completion.) I could put these job-ids into a text file, "job-id.txt", each id in its own line.For each job-id, the script would ask me few questions (with a yes or no answers) to see if I want to do some other checks for each job-id.I want to know how may I direct my job-ids from this text file into the script one job-id at a time.

View 14 Replies View Related

Programming :: Bash Scripting - Parsing Text File By Character

Aug 11, 2009

Is there a way to process individual characters one-by-one from a text file in Bash, or is that hoping for a little too much from this lovable old clunker?

View 13 Replies View Related

Programming :: Parse Multiple Variable From Text File With Bash?

Jul 13, 2010

I am trying to think of a logic where my file contains some data I had to read and do some processing. Issue is that file contains data multiple times. For example:

:::::::::::
var1=value1
var2=value2

[code].....

I have to read first paragraph of variables and do some processing and then move on until the end of file. Variable names are same in whole file but for each paragraph the value is different. I can't think of a logic to attain this task. How can I do it? It should be a simple bash script, but I am not able to work out.

View 2 Replies View Related

Ubuntu :: Bash Script To Delete/replace A Specific String Of Text?

Jun 17, 2010

What i want to do is pretty simple.I want to uncomment every line that begins with "deb" (except for deb cdrom) in /etc/apt/sources.list.I know how to do this through system > administration > software sources.I know I can gksu gedit /etc/apt/sources.list.I'd rather not do it that way.I'd rather have a script do it. It's less work, less typing, less clicking, and would work the same on every ubuntu version.

View 8 Replies View Related

Software :: Find And Delete String In Text Files?

Mar 6, 2010

I have a series of file names in a text file that I generated by running
Code:

bash-4.1# ls -alt *.txz | awk '{print $8}'
and then copy pasting the output. All of these file names have the version number
Quote:
-4.4.1-x86_64-1alien.txz

I just want a method to remove that version number from all the filenames so that I can then add all the packages without version numbers to a blacklist file.

I've tried kwrite and mousepad and both have a search feature and a replace feature but I haven't been able to just have the text removed successfully.

View 3 Replies View Related

Programming :: Put String On Top Of Text?

Jul 28, 2010

I want to create a script wherein it will put a string somewhere on the text file. I tried to create a script using redirect ">" and then put it on top of the file.

The text contains code...

View 6 Replies View Related

Programming :: Bash Text To Variable Accessing Individual Text Lines?

May 2, 2010

i am on processing text tasks And i found that if you assign a text to a variable is chomp'ed automatically the newline

Code:

variable=$(cat file.txt)

The problem is i can only access the items/lines using:

Code:

for line in $variable
do
echo $line
# Other commands
done

how do i convert this to an indexed array. More importantly, how do i get access to individual $line[0], ..., $line[n] Another thing, if the file.txt, has lines with spaces it is a mess using the for...in..., but echoing prints line by line...o_0

View 11 Replies View Related

Programming :: Bash - Recursive Find - Create Parent Folder - Moving File

Dec 5, 2010

I'm starting bash shell script and I'm looping without any solution.

I'm trying to find some files under a folder hierarchy and in case of errors moving these files to a destination folder under the same hierarchy recreating this hierarchy if not exists.

Finding all ._* files under /src and moving them to /dest recreating folder1 or the others which contains ._* files but without moving files which does not correspond to the pattern.

Code:

I tried find command and I'am getting all needed files

Code:

But I don't know how to use the output to get the parent folder of files which are found to

1- create folder with mkdir -p /dest/folder1 or /dest/folder1/folder4

2- move found files from /src/... to /dest/... with rm command

I'm working on a find command as this trying to do all in the same line but ... little lost

Code:

View 8 Replies View Related

Software :: Check The Contents Of A Text File For A Specific String And Remove It From The File From The Command Prompt?

Oct 14, 2010

I want to be able to check the contents of a text file for a specific string and remove it from the file from the command prompt. I would basically be searching through a number of files and if a specific string is found I would like it removed automatically. pretty much a find and replace, were the replace is nothing. any one got any ideas on how you would do this. I already have the search part sorted just need to be able to remove the string I don't want from the multiple files.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved