unix

How to implement grep in bash scripting? [duplicate]

倾然丶 夕夏残阳落幕 提交于 2020-12-13 17:57:15
问题 This question already has answers here : How to perform grep operation on all files in a directory? (5 answers) Closed 18 days ago . I am working on to search a string on files using grep in a directory(in for loop) for file in .* *; do if [[ -f "$file" && `grep -r "$pattern" "$file"` ]]; then path=`pwd`/"$file" echo "$path" fi done 回答1: Avoid the for loop and use something like grep -l "${pattern}" ${PWD}/.* ${PWD}/* or better find ${PWD} -type f -exec grep -l "${pattern}" {} + 回答2: Use find

How to implement grep in bash scripting? [duplicate]

◇◆丶佛笑我妖孽 提交于 2020-12-13 17:56:25
问题 This question already has answers here : How to perform grep operation on all files in a directory? (5 answers) Closed 18 days ago . I am working on to search a string on files using grep in a directory(in for loop) for file in .* *; do if [[ -f "$file" && `grep -r "$pattern" "$file"` ]]; then path=`pwd`/"$file" echo "$path" fi done 回答1: Avoid the for loop and use something like grep -l "${pattern}" ${PWD}/.* ${PWD}/* or better find ${PWD} -type f -exec grep -l "${pattern}" {} + 回答2: Use find

Use of Awk filter to get the students records details in descending order of total score

大憨熊 提交于 2020-12-13 03:40:30
问题 Student details are stored in a file system as follows: Roll_no,name,socre1,score2 101,ABC,50,55 102,XYZ,48,54 103,CWE,42,34 104,ZSE,65,72 105,FGR,31,45 106,QWE,68,45 Q.Write the unix command to display Roll_no and name of the student whose total score is greater than 100 the student details are to be displayed sorted in descending order of the total score. total score as to be calculated as follows :- totalscore=score1+score2 file also content the header(Roll_no,name,socre1,score2) My

Login script using Python and SQLite

巧了我就是萌 提交于 2020-12-06 23:36:22
问题 I'm trying to create a login script using SQLite to store the user data. Any ideas on how to to that? I have research over hours and found nothing of the kind. I would appreciate any help! :) This is what I got so far: user = raw_input "User:" pswd = getpass.getpass "Password" db = sqlite3.connect('/SABB/DATASETS/SENHAS') c = db.cursor() c.execute('SELECT 1 from sabb WHERE usuario = "user"') ('SELECT 1 from sabb WHERE senha = "pswd"') if c.fetchall() is True: print "Welcome" else: print

How to find grid points nearest to given location using shell script?

纵饮孤独 提交于 2020-12-06 12:53:06
问题 I have two different files. Part of those files are: file 1: ifile1.txt 21 10.3 70.32 09 32 11.3 71.43 10 33 15.4 75.00 00 54 17.3 68.03 12 95 19.2 65.02 21 99 20.1 80.10 11 and so on...... Where 1st column is the ID, 2nd column refers to x-axis, 3rd column refers to y-axis, 4th column refers to value file2: ifile2.txt 10.10 70.12 10 10.11 73.33 08 11.05 72.40 00 11.30 69.13 15 12.00 64.02 27 12.05 79.20 25 13.10 80.32 10 13.11 75.43 06 14.05 74.00 02 14.20 69.03 15 16.40 65.02 13 16.55 68.10

Record Bash Interaction, saving STDIN, STDOUT seperately

烈酒焚心 提交于 2020-12-05 11:49:25
问题 So I want to record my bash interaction, which I know I can do with script, or ttyrec. Except I want one feature more than they have. Save input (i.e STDIN), and output (i.e. STDOUT) separately. So something like (where I typed the first "Hello World!"), except of course script takes one [file] arg, not two: user@pc:~$ script input.txt output.txt Script started user@pc:~$ paste > textfile.txt Hello World! user@pc:~$ cat textfile.txt Hello World! user@pc:~$ exit Script done So input.txt looks

gcc: Link Library In Same Folder As Source Files

社会主义新天地 提交于 2020-12-05 11:12:33
问题 I'm trying to compile a C project using gcc . All source files and the .a library file are in the same folder . How can I successfully compile the project? I've tried: gcc -o test main.c IPT.c logitem_list.c -L -./ -libpt But I receieve error: /usr/bin/ld: cannot find -libpt collect2: error: ld returned 1 exit status 回答1: You specify the directory to -L and the 'core' name to -l : gcc -o test main.c IPT.c logitem_list.c -L . -lpt When given -l pt , the linker looks for libpt.a or libpt.so or

gcc: Link Library In Same Folder As Source Files

孤者浪人 提交于 2020-12-05 11:11:09
问题 I'm trying to compile a C project using gcc . All source files and the .a library file are in the same folder . How can I successfully compile the project? I've tried: gcc -o test main.c IPT.c logitem_list.c -L -./ -libpt But I receieve error: /usr/bin/ld: cannot find -libpt collect2: error: ld returned 1 exit status 回答1: You specify the directory to -L and the 'core' name to -l : gcc -o test main.c IPT.c logitem_list.c -L . -lpt When given -l pt , the linker looks for libpt.a or libpt.so or

Label can only be used as part of a statement Error

六眼飞鱼酱① 提交于 2020-12-02 06:47:08
问题 I have been looking through the forums but I have not found an answer to this question that applies to my situation. I am trying to make a system call to using 'sort' (unix), however, I receive an error saying, "a label can only be part of a statement and a declaration is not a statement." Here is the code causing the error. int processid; switch(processid = fork()){ //establishing switch statement for forking of processes. case -1: perror("fork()"); exit(EXIT_FAILURE); break; case 0: char

Label can only be used as part of a statement Error

与世无争的帅哥 提交于 2020-12-02 06:42:24
问题 I have been looking through the forums but I have not found an answer to this question that applies to my situation. I am trying to make a system call to using 'sort' (unix), however, I receive an error saying, "a label can only be part of a statement and a declaration is not a statement." Here is the code causing the error. int processid; switch(processid = fork()){ //establishing switch statement for forking of processes. case -1: perror("fork()"); exit(EXIT_FAILURE); break; case 0: char