w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Bash script to grep through one file for a list names, then grep through a second file to match those names to get a lookup value
awk -v search="$search_string" '$0 ~ search { gsub(/"/, "", $5); print $1" "$5; }' "$filename" | while read line do result=$(awk -v search="$line" '$0 ~ search { print $3; } ' "$lookup_file"); # Do "something" with $result done

Categories : Bash

script file: name editing and renaming using PowerShell
You can use Get-Child item with recursive option to load all the jpg files and rename it using Rename-item command. Get-ChildItem -r -path "C: est" *.jpg | % { if(!$_.PSIsContainer -and $_.Name.Contains('_')) {Rename-item $_.FullName ( $_.BaseName.Split('_')[1] +"p" + $_.Extension) } }

Categories : Windows

No effect on my detailview when performing an action in a popover
It could be a number of things but the question is a little light on details. Have you confirmed that detailViewController is a valid object (!= nil)? Are you using nibs? If so, have you double checked that your outlets are linked properly? I'd include more details if you've still got issues.

Categories : IOS

Unix script to recursively search a directory and sub directories to grep and print content between 2 patterns in file
This might work for you: find . -type f -exec awk 'BEGING {print FILENAME ":"} /Pattern1/ { p=1 ; next } /Pattern2/ {p=0} p==1 {print $0} END {print ""}' {} ; Note, this prints the FILENAME, even if Pattern1 was not found!

Categories : Unix

How to grep $ sign in script
grep 'devnode "^sda[1-9]?$"' file Grep understands two different versions of regular expression syntax: "basic" and "extended." grep 'foo' file / use Basic Regular Expressions grep -E 'foo' file / use Extended regular expressions. If use Basic Regular Expressions, ?, +, {, |, ( and ) have no special meaning. If use Extended Regular Expressions, like this. grep -E 'devnode "^sda[1-9]?$"' file

Categories : Shell

Shell Script: grep and replace
Change this line: sed -e "s/down/up/g" test.htm To this: sed -i -e "s/down/up/g" test.htm The -i flag means to edit the file "in-place" rather than to write the replacements to standard output.

Categories : Shell

bash script for conditional grep
This will do the trick : parity=0 for val in $(grep -E "errorCode|id" x.json|grep -Eo [0-9]+) do if [ $parity -eq 0 ] then if [ $val -eq 1 ] then parity=1 fi else echo "id $val is erroneous" parity=0 fi done where x.json is the jason file.Replace the line containing echo command with a suitable statement as per your requirement. For example, if you are appending the id to a error log, try : echo $val >> erroneousIDs.log NB : I assumed that the ordering of the fields will always be the same.

Categories : Linux

bash script with grep and cut : command not found
In this line: result=`$callResult >> grep 'RESPONSE CODE' | cut -d':' -f 2` You should be piping output to grep, not redirecting. Change it to this: result=`$callResult | grep 'RESPONSE CODE' | cut -d':' -f 2` Also, the syntax is a bit off, and you're better off avoiding backticks when possible. This is even better: result="$(echo ${callResult} | grep 'RESPONSE CODE' | cut -d':' -f 2)"

Categories : Bash

Using a bash script to grep an integer and compare it to another
This happens when there was no match, $score is then the empty string. A simple fix: #!/bin/bash for f in `ls $1/*.html` do score=`grep -o -P '(?<=ADJ. SCORE: )-?[0-9]?[0-9]' $f` if [ -z $score ] then echo "No match in '$f'" else if [ "$score" -lt 36 ] then cp "$f" "$2" fi fi done I think you also need to be more aware of quoting requirements in shell scripting.

Categories : Bash

Using the output of a 'grep search' as the input of a 'yum update' (Shell Script)
You have two options of how to call a command (yum in your case) with output of another command (grep in your case): one is to do something like: $ yum update $(find-repos-of-install | grep rpmfusion) Another one is to use xargs, something like: $ find-repos-of-install | grep rpmfusion | xargs yum update

Categories : Shell

Crontab editing not working in Php script
First for the syntax: it's crontab -e With this command you open the crontab of the current user, if you want to change some cron information from a different user you have to use this syntax: crontab -u your-user-here -e But this opens a default text editor. If you really want to edit the crontab of a different user with php, you have to read the content of the file, edit it and then write it back. You must keep in mind that you can't edit all cron files, cause of user permission.

Categories : PHP

How can I return grep results one line at a time in order to use the parsed data in another script?
You can use a for loop and a subshell anytime you have this pattern where you want to act on the result of a pipeline: for ip in $( nmap -sL 10.111.1.0/24 | grep android | grep -oE '([[:digit:]]{1,3}.){3}[[:digit:]]{1,3}' ); do echo "W00t! I found this ${ip}" /path/to/script "${ip}" done

Categories : Linux

Linux XML Editing from Command Line / Shell Script
I wouldn't try to use sed to edit XML. Unless there is some constant to match on (that lets you decide if you are on a /1 or /2) it'll be hard (I would say impossible, but some sed guru will chime and and prove me wrong...) If you can't install stuff, something like an awk or perl script that lets you keep a minimum of state you work better than sed.

Categories : Xml

Matlab Query: Image Processing, Editing the Script
There are few ways you could store an image in a kind of an array structure in Matlab. You could use array of structs. In that case you could do as you did: nova(i).img = imread([myDir B(i).name]); You access first image with nova(1).img, second one with nova(2).img etc. Other way to do it is to use cell array (similar to arrays but are more flexible in the sense that members could be of the different type): nova{i} = imread([myDir B(i).name]); You access first image with nova{1}, second one with nova{2} etc. [ IMPORTANT ] In both cases you should remove this line from code: nova = zeros(1,nfile); I suppose you've tried to pre-allocate memory for images, and since you're beginner I advise you not to be concerned with it. It is an optimization concern to be addressed if you c

Categories : Image

grep exact word match (-w) does not work with file paths in a text file
You can use egrep like this: egrep "(^| )$file1( |$)" "$file2" If file1="run" then above command will match string run preceded by line start or space and followed by space or line end.

Categories : Linux

grep from file doesn't write result to an output file
> keeps overwriting the file. Use >> to append to it. Instead of using a loop, you can simply use the -f option in grep to make grep read patterns from the file. grep -f file1.csv file2.csv > result.csv If you have to use a loop, use the following approach: while read line; do grep "$line" ./file2.csv done < file1.csv > result.csv

Categories : Bash

How to use sed / awk / grep … to extract blocks from a file and each block save it into a file
This code should create files named resultNUM where NUM is a number of the block awk '/PATTERN/{close("result"f);f++}{print $0 > "result"f}' file.log

Categories : Regex

Is it better to use git grep than plain grep if we want to search in versioned source code?
git grep only searches in the tracked files in the repo. With grep you have to pass the list of files to search through and you would have filter out any untracked files yourself. So if you are searching for something that you know is in the repo, git grep saves you time as all you have to do is provide the pattern. It also is useful for not having to search through anything that is untracked in the repo.

Categories : Linux

Script in php to create acrylic effect on image
If you have access to imagemagick's convert utility you can do this. Also looking throught here may give you some luck.

Categories : PHP

Performing calculations on a tab-delimited file
Use collections.defaultdict with list as the default argument. Take the value from the first column as the key, and append the second value. import csv from collections import defaultdict # Gather the data from the CSV file d = defaultdict(list) with open('data.csv', 'r') as csvfile: reader = csv.reader(csvfile, delimiter=' ') for row in reader: d[float(row[0])].append(float(row[1])) # Print the mean. for k in d.keys(): print k, sum(d[k])/len(d[k])

Categories : Python

Does file descriptor performing IO needs processor cycles?
"Does file descriptor performing IO needs processor cycles?" No. File descriptor does not do I/O. It is just used by OS to do I/O for application program. The OS do I/O through DMA or Interrupt machanism, both of which need a few processor cycles to handle context switch.

Categories : Linux

grep command on linux ( especially grep --exclude)
you can find grep on man pages here. what exclude does: --exclude=PATTERN: Recurse in directories skip file matching PATTERN. your command will search, recursively, in all directories, skipping file pattern "*.svn*" and searching for file pattern "1.0.0.8/*1.0.0.8.config > 1.0.0.8-REVISION.txt"

Categories : Linux

grep -R one result per file
The cut in your command suggests that you're looking to list files matching the specified string. find . ! -path "*/manual/*" ! -path "*/include/*" -type f -exec grep -Fl 2.2.24 {} ; should work for you.

Categories : Linux

Grep for Pattern in File in R
Let's take a look at what your regular expression means. [A-Z0-9] means any capitalized letter or number and {12} means the previous expression must occur exactly 12 times. The string CONCENTRATIO is 12 capitaized letters, so it's no surprise that grep picks it up. If you want to take out the matches that match to just letters or just numbers you could try something like allleters <- grep("[A-Z]{12}",strings) allnumbers <-grep("[0-9]{12}",strings) both <- grep("[A-Z0-9]{12}",strings) the matches you wanted would then be something like both <- both[!both %in% union(allletters,allnumbers)] Someone with better regexfu might have a more elegant solution, but this will work too.

Categories : Regex

Why does 'top | grep > file' not work?
By default, grep buffers output which implies that nothing would be written to top.log until the grep output exceeds the size of the buffer (which might vary across systems). Tell grep to use line buffering on output. Try: top -b -d 1 | grep --line-buffered java > top.log

Categories : Linux

Remotely performing actions on another computer via batch file
You can use the PsExec tool from the PsTools collection to remotely run any command on a remote computer that you have access to. You would use it like below to run commands from a specific batch file name fileName. psexec \%ip% -u %user% -p %pass% fileName

Categories : Batch File

AIX: using grep command to log two lines from a file
Why don't you do it like this? grep -Ei "USR02|USH02|TCURR|REGUH|LFB1|LFA1" -B 2 file grep -e admits multiple parameters. So instead of grep -i ONE and then grep -i TWO, you can do grep -Ei "ONE|TWO". With -B 2 what you do is to print the two previous lines of the matched line. Test All together will make the following: $ grep -Ei "USR02|USH02|TCURR|REGUH|LFB1|LFA1" -B 2 file Tue Jul 2 08:42:16 2013 +02:00 LENGTH : '222' ACTION :[68] 'update SAPPRD.USR02 set uflag=64 where BNAME='CANAS' and MANDT='000'' and if you do not want the line in the middle, $ grep -Ei "USR02|USH02|TCURR|REGUH|LFB1|LFA1" -B 2 file | grep -v LENGTH Tue Jul 2 08:42:16 2013 +02:00 ACTION :[68] 'update SAPPRD.USR02 set uflag=64 where BNAME='CANAS' and MANDT='000'

Categories : Shell

Color text in a file using grep
see the screenshot, if it is what you are looking for. In this case, the two words are foo and bar If yes, you could try the grep regex in screenshot.

Categories : String

Grep a YAML file in Perl
LoadFile returns a hash reference. my $href = YAML::LoadFile("file.yaml"); Check CPAN for any deep data structure traversing module, e.g. http://p3rl.org/Data::Walk http://p3rl.org/Data::Visitor http://p3rl.org/Data::Diver

Categories : Perl

Filtering file in unix using grep/sed/awk other?
One way using sed. For every field that begins with Record read next one and try to match the string unique .... If it doesn't suceed, print both adding a newline. sed -n '/^Record/ { N; /unique constraint .* violated/! { s/$/ /; p } }' infile It yields: Record 2: Rejected - Error on table DMT_. ORA-01400:cannot insert NULL in to("DM"."DMT_INSURANCE"."INSURANCE_FUND_CODE") Record 4: Rejected - Error on table DMT_ADDRESS, column ORIGINAL_POSTCODE. ORA-12899: value too large for column "DM"."DMT_ADDRESS"."ORIGINAL_POSTCODE" (actual: 12, maximum: 10)

Categories : Linux

Grep file with two columns as input
You can use something like sed to construct patterns for grep: $ grep -Ef <(sed -r 's/(.*);(.*)/^[^;]*;[^;]*2[^;]*;([^;]*;){2}[^;]*1/' file2) file1 "ALMEREWEG ";" 50 ";" ";"ZEEWOLDE ";"3891ZP" "ALMEREWEG ";" 53 ";" ";"ZEEWOLDE ";"3891ZN"

Categories : Bash

Need to remove the path from the output of a grep but not the file
I am not sure if there is a way to suppress the path if you do grep outside the directory. You can however, use awk to strip the path. Something like: awk -F/ '{print $NF}' <(grep -e "string1" -e "string" /home/username/scriptfolder/logs/my_fliles*) > destination

Categories : Shell

Match empty lines in a file Grep
grep and count empty lines like this: grep -c "^$" myfile.txt As is considered end of line you need to use line start and line end "^$"

Categories : Regex

Extract strings in a text file using grep
for line in `cat text.txt`; do grep $line input.txt >> output.txt; done Contents of text.txt: ABCB8 ABCC12 ABCC3 ABCC4 AHR ALDH4A1 ALDH5A1 Edit: A safer solution with while read: cat text.txt | while read line; do grep "$line" input.txt >> output.txt; done Edit 2: Sample text.txt: ABCB8 ABCB8XY ABCC12 Sample input.txt: You were hired to do a job; we expect you to do it. You were hired because ABCB8 you kick ass; we expect you to kick ass. ABCB8XY You were hired because you can commit to a rational deadline and meet it; ABCC12 we'll expect you to do that too. You're not someone who needs a middle manager tracking your mouse clicks If You don't care about the order of lines, the quick workaround would be to pipe the solution through a sort | uniq: cat text.txt |

Categories : String

python - How to grep for numbers from log file and do summing
What about using csv module: import csv with open('logfile') as f: reader = csv.reader(f, delimiter=" ") print sum(int(line[-1]) for line in reader) prints: 477594 for your example data.

Categories : Python

Editing the file in Qt
This works for me: #include <QCoreApplication> #include <QFile> #include <QIODevice> #include <QTextStream> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QFile inFile("input.csv"); if(!inFile.open(QIODevice::ReadOnly)) exit(1); QString newFileData; QTextStream in(&inFile); //Read file line by line until it reaches the end while(!in.atEnd()) { QString line = in.readLine(); newFileData.append(line); int positionOfLastChar = newFileData.length()-1; char lastChar = newFileData.at(positionOfLastChar).toLatin1(); //Returns the character bevore the last character if(lastChar == ',') newFileData.remove(positionOfLastChar, //Remove at the position of the

Categories : C++

How can I use awk or grep to capture an entire Python traceback in a log file?
Here's an AWK script I tried whipping together. awk '{a[NR]=$0}; /KevinCustomError/ {for(i=0; a[NR-i] !~ /Traceback/; i++) {} i++; while(i-- >= 0) {print a[NR-i]}}' logfile Or, in file form. {a[NR] = $0}; { if ($0 ~ /KevinCustomError/) { for (i = 0; a[NR-i] !~ /Traceback/; i++) {} i++ while (i-- >= 0) { print a[NR-i]; } } } Used like: awk -f logscript.awk logfile. Not too familiar with AWK, so any criticism is welcome. Basically, it keeps track of all lines read so far, and just searches backwards to find a "Traceback" token (which you can replace if you'd like), and then prints everything in between (in the correct order).

Categories : Python

How to add the txt file name ahead of each line ? (with notepad++, or grep command, or ..)
I think, you can use grep. As manpage says, -H, --with-filename Print the file name for each match. This is the default when there is more than one file to search. I've checked this on my machine: if you specify relative path ./*.txt it will print out the relative names, but if you specify full path /some/path/*.txt it will print full path to files. So, you can grep output of the first grep and do whatever you want with data.

Categories : Regex

magit-grep, how to include or exlude file extensions?
One possibility is a combination og git-grep and git-ls-files: git grep ... `git ls-files | grep -- '.html$'` But this works only if the output of git-ls-files does not exceed the maximum command line size on your system (which is a couple of 100K on modern systems).

Categories : GIT

How to make grep to stop searching in each file after N lines?
I don't know if it would be faster but you could do this with awk: awk '/match me/{print;exit}FNR>50{exit}' *.mail will print the first line matching match me if it appears in the first 50 lines. (If you wanted to print the filename as well, grep style, change print; to print FILENAME ":" $0;) awk doesn't have any equivalent to grep's -r flag, but if you need to recursively scan directories, you can use find with -exec: find /base/dir -iname '*.mail' -exec awk '/match me/{print FILENAME ":" $0;exit}FNR>50{exit}' {} + You could solve this problem by piping head -n50 through grep but that would undoubtedly be slower since you'd have to start two new processes (one head and one grep) for each file. You could do it with just one head and one grep but then you'd lose the abi

Categories : Linux



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.