unix

Intersection of files

*爱你&永不变心* 提交于 2021-02-13 03:45:29
问题 I two large files (27k lines and 450k lines). They look sort of like: File1: 1 2 A 5 3 2 B 7 6 3 C 8 ... File2: 4 2 C 5 7 2 B 7 6 8 B 8 7 7 F 9 ... I want the lines from both files in which the 3rd column is in both files (note lines with A and F were excluded): OUTPUT: 3 2 B 7 6 3 C 8 4 2 C 5 7 2 B 7 6 8 B 8 whats the best way? 回答1: awk '{print $3}' file1 | sort | uniq > file1col3 awk '{print $3}' file2 | sort | uniq > file2col3 grep -Fx -f file1col3 file2col3 | awk '{print "\\w+ \\w+ " $1 "

Intersection of files

≯℡__Kan透↙ 提交于 2021-02-13 03:43:16
问题 I two large files (27k lines and 450k lines). They look sort of like: File1: 1 2 A 5 3 2 B 7 6 3 C 8 ... File2: 4 2 C 5 7 2 B 7 6 8 B 8 7 7 F 9 ... I want the lines from both files in which the 3rd column is in both files (note lines with A and F were excluded): OUTPUT: 3 2 B 7 6 3 C 8 4 2 C 5 7 2 B 7 6 8 B 8 whats the best way? 回答1: awk '{print $3}' file1 | sort | uniq > file1col3 awk '{print $3}' file2 | sort | uniq > file2col3 grep -Fx -f file1col3 file2col3 | awk '{print "\\w+ \\w+ " $1 "

script to read a file with IP addresses and login

梦想与她 提交于 2021-02-11 18:14:43
问题 I have a file named "host.txt" with listing IP addresses of two systems. ~] cat hosts.txt 10.1.1.10 10.1.1.20 Using below script I am trying to login to each system, check status of a service and print the output of each system. The script prompts to login, however does not continue to execute the /opt/agent.sh status command. Can someone please help fix this script? #!/bin/bash for HOST in `cat hosts.txt` do ssh root@$HOST STATUS=`/opt/agent.sh status | awk 'NR==1{print $3 $4}'` echo $STATUS

How to exclude some files from the loop in shell script [duplicate]

人走茶凉 提交于 2021-02-11 15:37:54
问题 This question already has answers here : for-loop for every folder in a directory, excluding some of them (5 answers) Closed 12 months ago . #! /bin/sh for file in $Files/*.txt; do chmod 777 $file done It will give permission 777 to all .txt files but I've 7 other .txt file for which I don't want to give 777 permission. How can I do that? 回答1: you can add a conditional check as below. As there's no clear attribute differentiating the files you want to exclude, you'd need to specifically check

How can find similarity between sentences? [closed]

依然范特西╮ 提交于 2021-02-11 14:54:40
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last month . Improve this question I'm trying to find similarities between both the sentences in a shell script. Have a two sentences containing duplicate words, for example, the input data in file my_text.txt Shell Script. Linux Shell Script. The intersection of both sentences: Shell + Script The union " size "

awk bash avg calculation in file

夙愿已清 提交于 2021-02-11 14:41:49
问题 write the unix command to display roll, name and avg of all students whose score is more than 50 in each subject and average is more than or equal to 75. avg can be calculated as (subj_1+subj_2)/2. input: roll ,name,subScore1,subScore2 123,a,88,78 101,b,76,90 812,c,78,98 output: 123 a 83 812 c 78 my code: awk 'BEGIN {FS=',';OFS=' '} {if(NR>1 (&& $3>50 && $4>50) && ($3+$4)/2 >= 75){print $1,$2,($3+$4)/2}}' input_file I don't know why I'm getting error. please help guys. 回答1: EDIT: Adding more

Merging word counts with Bash and Unix

本秂侑毒 提交于 2021-02-10 19:52:28
问题 I made a Bash script that extracts words from a text file with grep and sed and then sorts them with sort and counts the repetitions with wc , then sort again by frequency. The example output looks like this: 12 the 7 code 7 with 7 add 5 quite 3 do 3 well 1 quick 1 can 1 pick 1 easy Now I'd like to merge all words with the same frequency into one line, like this: 12 the 7 code with add 5 quite 3 do well 1 quick can pick easy Is there any way to do that with Bash and standard Unix toolset? Or

Merging word counts with Bash and Unix

旧巷老猫 提交于 2021-02-10 19:51:53
问题 I made a Bash script that extracts words from a text file with grep and sed and then sorts them with sort and counts the repetitions with wc , then sort again by frequency. The example output looks like this: 12 the 7 code 7 with 7 add 5 quite 3 do 3 well 1 quick 1 can 1 pick 1 easy Now I'd like to merge all words with the same frequency into one line, like this: 12 the 7 code with add 5 quite 3 do well 1 quick can pick easy Is there any way to do that with Bash and standard Unix toolset? Or

can't make locale work on Linux

可紊 提交于 2021-02-10 18:51:52
问题 I am writing an PHP application and using the gettext module to translate to different languages. The code is working as I expect on my local computer (Windows running WAMP), but i can't make it work on the server (Unix + apache2) { $locale_folder = dirname(dirname(dirname(__FILE__))).'/locale/'; $locale = 'he_IL'; $domain = 'myapp'; $autoreload = true; // activate the locale setting setlocale(LC_ALL, $locale); setlocale(LC_TIME, $locale); putenv("LANG=$locale"); putenv("LANGUAGE=$locale");

can't make locale work on Linux

耗尽温柔 提交于 2021-02-10 18:51:34
问题 I am writing an PHP application and using the gettext module to translate to different languages. The code is working as I expect on my local computer (Windows running WAMP), but i can't make it work on the server (Unix + apache2) { $locale_folder = dirname(dirname(dirname(__FILE__))).'/locale/'; $locale = 'he_IL'; $domain = 'myapp'; $autoreload = true; // activate the locale setting setlocale(LC_ALL, $locale); setlocale(LC_TIME, $locale); putenv("LANG=$locale"); putenv("LANGUAGE=$locale");