Programming :: Shell To Remove Line Matched With Variable?
Jul 25, 2011
I'm using sed to remove certain line in a text file based on a match with 2 variables from input. Here is how it looks like in file
Philip S:Odds:45:343
Mike Junior:Odds:3:56
I prompt for 2 inputs in variable form which is compared to the first 2 fields of the above text (: seperated). So say i enter Philip S and Odds then it should delete the entire first line.
I am writing a bash script to run everyday and output results to a file. When the same results are produced i want to overwrite the line from the previous day. (Or remove and add). So if the script finds a variable in a line. i want it to output the results to that line . sed -i did not work for me; sed: couldn't open temporary file ./sedTvOCEg: Permission denied
Is there any way to add a character to the end of a line when a certain match text is matched. I have a text file where any line that contacts text XYZ a z is placed at the end.
Using things like awk/sed, but have managed to cobble together what I needed so far without a problem. The only thing I'm struggling with is to assign the content of a particular line as a variable, and then to use it again throughout the file.
For example, if what I want is the first line of the file to become the variable "from1", and then to replace the word "Subject" in the file with the string "Message from [from1]". What I thought would work
I tried a few diff combinations but nothing seems to work. All I get is the terminal hanging indefinitely.
I have some messy code that I wrote a while back and I am trying to organize it. The program opens xpaint and uses xwit and xte to draw packman and so on. I want to split it all up I am going to add more to it. Basically like i would want drawing packman in one function i guess you could call it and then coloring him or the background in another
#xwit -id $paintersMom -focus -raise #sleep 1 #xwit -id $paintersMom -warp 30 390 #// fill in command on tool bar #sleep 1 #xte 'mouseclick 1' #sleep 1 #xwit -id $canvasWin -warp 221 40 #// color selection #sleep 1 #xte 'mouseclick 1' #sleep 1 #xwit -id $canvasWin -warp "$(($X-150))" "$Y" #//location on pac man #sleep 1 #xte 'mouseclick 1' #sleep 1
#xwit -id $canvasWin -warp 62 44 #// selecting color black #sleep 1 #xte 'mouseclick 1' #sleep 1 #xwit -root -warp 62 120 #// selecting back to canvas #sleep 1 #xte 'mouseclick 1' #// color canvas black #sleep 1 #xwit -id $paintersMom -focus -raise #xwit -id $paintersMom -warp 27 108 #//click back to pencil #sleep 1 #xte 'mouseclick 1' #sleep 1 </code>
Here for example $paintersmom is would be in the drawing of pacman but I would also want to use it when I colored him in.. but I would want both processes in a different shell script.
What I am trying to accomplish is a way to read only the lines that have been added to the file mylog0 since the last time the script looped (5 seconds). I am open to new suggestions too, I have been stuck on this little script for a few hours already.
The above command does exactly what I want: limit the search of files in $SEARCHDIR to those specified by --include.
I use double quotes rather than single quotes because of the shell variables. I would have thought this would cause the shell to expand the "*" but this doesn't seem to be the case.
I am doing a mysql query with a bash shell script like: mysql translator -u root --password=******** -e "SELECT word FROM tagalog ORDER BY RAND() LIMIT 1" | while read line; do echo $line
So when I echo the value of $line I get: word magandang umaga "word" is the name of the row in the table and maganda umaga is a randomly selected choice from the row. Is there a way i can remove the name of the row from the variable $line. With a result that will allow me to echo $line and output only the randomly selected entry in from the row e.g. magandang umaga
this would remove the Last character of the value assigned to the %host%. for example if my value is: abcd i get abc. but i am not able to assign the output. for example when i do
Quote:
set k=`echo %host%|sed "$s/.$//"`
after doing echo %k i get no output at the command prompt...!! whereas when i just type:
Quote:
echo abcd|sed "$s/.$//"
at the command prompt i get abc. maybe some other ways to Remove the Last character...?
I need to check whether a shell script variable contains non-zero numeric data to proceed. The variable should contain numeric values, but may in fact contain zeroes, blank space or nothing. So far, I have tried various combinations of:
Code: if test $variable then if test $variable -gt 0 then echo "good data exists" else "no good data exists" fi fi It partially works, but I get either "too many arguments" or "integer expression expected".
I want to get the last term of an unknown-sized text line, by usig the awk command. Is there any variable which points to the last term of a text line ? (obviously, y can obtain that term if i knew how many terms does the line have... i.e. awk '{print $12}' ; if we are talking about a 12-terms text line) I wonder if there is an option like $?, to get the last term.
I want to append a variable string to the end of a specific line. not like append the same string to each line. like in my file i have 4 columns, i want to add a string in 5th column in some fixed row.
instead of importing a file I would like to use the variable $x I tried using pipes, but with no luck. My goal is to read one line at a time, but not have to export my data to another file, I would like to keep it all within one script.
I am loading the file in Fortran. File looks something like this (shown below) I am interested in Velocity values and not Pressure values. Is there a way to code in Fortran which finds the staring LINE of Velocity values and ending LINE of values or I have to manually find the lines? IN this case it should return Starting line : 9 Ending line: 11
now i want to delete the line which first column content is 1. so, if i pass the parametere 1 to function delete_row. is should remove the first row as
I am bouncing a file across platforms (windows->solaris->mainframe), and the file is starting out with a "special" character (the registered trademark "circle R") in some of the records. This character is not in the EBCDIC character set on the MF, so it is unrecognizable. The MF developer I am working with asked if it is possible to replace the character with a specific hex value (AF) before it gets to the MF.
I was putzing around with sed, tr, etc. on the ksh command line, hoping to find an easy way to get one of them to substitute hex instead of ASCII. I have found that the usual shell utilities recognize the trademark character, so homing in on what to replace is solved. But I cannot get anything to actually substitute in the hex sequence I want. E.g. I was thinking something like...
>cat special_file | sed 's/R/AF/g'
But my version of sed does not seem to have hex "editing" capability.
I am beginner in this business of shell script and I have no idea how to do the following: I would like to replace the lines of my file that contains 'CFL=' by 'CFL=0.5'. Note that I want to replace the full line meaning
I'm having a bit of a headbanger trying to work this one out. I'm trying to remove all of the characters on a line apart from the last 17. For example, I need to change this:
I have a big csv-file wich is not formatted very well. I clean it up with removing a lot of html etc, but some of the lines breaks where they are not supposed to.What I want to do is to check next line, if it starts with 'PX' I don't want to do anything, but if it does not start with 'PX' I want to merge the two lines. That is removing the newline character on line one and replace it with a space.Can this be done with sed? (or maybe with perl or something, but I'm more familiar with sed)I've been looking und the net to find a solution, but to no result.
Inside a loop i'm populating a string variable. Because csh doesn't have very good support for arrays I thought of doing this. I want to add a new line character to the end of the concatenation each time the loop iterates. Then at the end print this variable out.
I tried " and some resources said it was just a "". Neither work. What am I doing wrong?