Quote:Originally Posted by topcatI would like to know how i can write a shell script to delete a line if a particular pattern exists?E.g. I have a text file with multiple lines. Say 1000s. in the following pattern.
If the patternusername@email.com exists then the line "username@email.com:149.0.3.4:1 should be deleted from the file.I have a very similar question but I need to delete one line in a file which matches one very precise instance of a string only. Let's assume I have a file composed of thousands of lines and let's call the file chap-secrets. Let's take the following sample entries:
Code: #USERNAME SERVER PASSWORD IP pp pptpd blahblah *
I'm trying to highlight some key words as tailing a log file using a perl script; about my case: I want to search for a keyworrs just once and highligt all occurrence of them. I want just highlit the keywords but not the whole line but the problems are that perl just catches the first keyword in a line and skip checking for other occurrence. for example if a line like "Error: some exception happen, Unable to process" it just highlight the error and do not process the remain part of the line where it should hilight the word "exception" and "Unable"
2-How can I do some action if for exapmle at least 4 time "unable" message appear ( not just in one line but diffrent line)in below is how I use perl search and replace : Code: s/(?:(unable|exception|warning))/e[1;31$&.......
Its my first post in here so please be patient I am trying to use regex in perl script to detect allowed words from the file and then print output to the screen.
As an example : I have text file with orders and returns :
My question: is it possible to make sure that i am ony outputing to the screen orders based on few conditions like Item,order form e.g. online.And is it possible to have multiple matches (Item2 only diplay if ordered online etc)
In a bash-script, only the case if a regular expression does not match is relevant.herefore I used the exclamation mark !. But where to place it?
These two work fine, but are they equivalent? Code: if ! [[ $abc =~ $pattern ]]; then or Code: if [[ ! $abc =~ $pattern ]]; then Where is the ! placed more correct?
What's the easiest way for me to make a program that requests a file location and then tar balls it. I basically want to start making a simple method of using pv with tar (lzma).
working on a script to update .Jar file, I have tried jar xf to unpack and jar cf to repack it is giving me java.lang.NoClassDefFoundError exception at main class. I also tried jar uf, which is also not working for me Basically my jar file requires to update date, which i do from "winrar" Manual it works fine, but now to remove "Donkey work", i want to make an script which does this all automatically, and the last stage is to update jar file which is not happening.
I would like to use the command line to compare two directories against each other. I have two folders called music collection that have evolved over the last year on two separate computers. 90% of the two folders are the same, but there are small differences. I would like a solution that will print out all the differences so I can analyze them and choose what I want to do with them, before merging the two folders. for example.I would like some kind of output that shows the differences and where its located.
comparing MusicCollection1 and MusicCollection2 dif1.mp3 located in MC1/folder1 (this one I might want to keep and merge over) dif2.mp3 located in MC2/folder3 (while this one I might realize does not exist in both folders because I deleted it for a reason)
I've looked at sort, uniq, and even tried scripting my own solution, but haven't come up with an elegant solution thus far. Its important that it is recursive because there are about 15 folders in Music collection and more folders under those 15.
I'm trying to write a script that takes two arguments, the first argument is a number, and the second argument is a filename. The shell script should indicate if the file's size is BIGGER or SMALLER the number provided. this is what i have sofar, am i on the write track, i'm hoping its just a problem with my if command
if [ $1 -h $2 ] then echo "$1 is bigger than $2" else
I want to compare zone file counting and same name, not records etc of master and slave dns server so that i sure both server contains same copy of the files at a time. Any utility to compare such files in linux?
#!/bin/bash ls -lhGg | while read line; do echo "$line"; done | awk ' { print $3" "$6 } '
what i want to do is be able to print column 3 and every column greater then 5. Has to be to the end of the line, since different filenames can have different amounts of words in them and the blank space is the separator. my current code works just fine if the file has no blank space.
How do I use bash to open a file, (file name as first parameter) cut n char from begin of each line, and write shortened lines to new file (outputfile name as the second parameter, n as the third parameter)
I have a laptop that I am in through SSH. The laptop does not have an Xwindow system so I am using the program fbi to open an image on my laptop screen from my SSH connection:
fbi -T 8 picture.jpg #this opens the image on the laptops tty8 terminal
I've found that making a for loop does not work with files that contain a space in the name. Something to due with a bug that they call a "feature" that stops the first variable at the first whitespace.
Using a "while" loop is not exactly what i require either seeing as I want to be able to view each image in the directory on screen and tag it accordingly, before it jumps off to the next image, and I'm not sure how to add a pause to a while loop.
How do I make a Bash script and loop Variables handle files like "files that contain spaces.jpg"
I would like to delete a single line from a file that contains many lines passing through the same values as the two parameters. Again, I would like to delete a single line and not all those that contain parameters. How can I make bash?
Using awk I pull the first field of a random line from my datafile.myvar1=`awk -F" " 'NR=='$randline' {printf "%s", $1}' myfileThis works fine. The problem is there will be empty lines at the end of the file. Rather than using awkto filter out blank lines I would like to figure this out first.So I test $myvar1 for a blank string after setting $randline to one that I know is blank:test -z "$myvar1" && echo "true" || echo "false"But, this returns "false"? So the string is not zero length. Why? It's a tab-separated file. Is awk storing the tab with the $1 field or something.This is where I get headache. I try to echo my variable to see what it looks like.
echo "$myvar1" outputs: nothing echo "My variable is [$myvar1]" outputs: [y variable is [
Why is the closing bracket at the beginning? What character could be stored in $myvar1 that would do such a thing and how did it get there?
This code uses ping to check connectivity to a remote location and logs it to a .html file which is then stylized by css..
Code:
#! /bin/bash path="$HOME/Desktop/IP_Monitor" #Path to write out files ALT="0" #For styling alternative row
[code]....
I need to add a feature such that instead of hardcoding the ip address .. it takes them from a list and makes new files for each ip address for logging.. And also when log files are completed , They should be compressed using tar. How should i go about adding both these.. This is my first bash script.
I have a script that reads part of a line, delimited between the first and second intended part by a colon. Then it "chops" the part after the colon, which are words offset by commas (counting them beforehand so as to catch every word in the string's second part), like this:
Code:
"COLORS.JPG:red,orange,yellow,green," (Returning) red
[code]....
single script that parses/breaks both parts of a line like this "COLORS.JPG:red,orange,yellow,green;blue,indigo,violet," so that the two parts, separated into single words (or two and three words, sometimes with spaces) can be used as single-line annotations and written to JPEG files using Exiv2. So far, I haven't been able to come up with a script that does this without one part of the total string(usually that part after the colon) becoming the first word in the second array. In other words, I look for this:
KEYWORDS:
[ ]red [ ]orange [ ]yellow
[code]....
Or vice-versa (ie, the second array winds up as a single-line "member" of the first). I think it's because I'm using a single while read loop to read the text file in which the filenames and substrings happen to be. If there's some way of reading a file once and going back to the beginning to read it again in another while loop, I haven't found it.
I am struggling with Bash scripting at the moment (I can't seem how anyone can write scripts with this language!!!) I have a need at home to have a cron job execute daily to lookup my downloads.txt file, read each url (per line) and download content from that url. Then that entry needs to be removed (well I keep all urls in memory and clear the file afterwards). If an error occurred during the download process, then the url is written to a downloads.err file. I got all the above working except for properly reading the url from the text file without including newline characters. I am using the following to read:
while read url; do --Do whatever here-- done < downloads.txt
How can I get it not to let the url variable have newline characters?
I have a file called list.txt with on word on each line that changes in length. I'd like to make a menu, each line being its own choice. I pieced together most of it the only thing missing is a failsafe for typing a number out of range
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.
I have two table files with x (1st column) ,y (2nd column) coordinates and intensity (3rd column). I need to match these two tables and divide the intensities at the consecutive coordinates on the 3rd column. The problem is the size of the tables are not same and I want to ignore the lines if they are not in one of the other file.
Im trying to compare two files and I only want to display the user names that are in the first file and not the second.
So I have one file named final.txt (which contains every user name and only the user names in a list no other information)
Then I have another file Over1.txt (which only contains certain users that have different permissions This file is also setup differently with the user name and some information about the user after the user name.
I need a way to compare final.txt to over1.txt so that I will only display the names that are in final.txt but not Over1.txt
Ive tried using diff and comm but just cant seem to get it two work correctly. Im not sure if im missing a option or what.