I have two files with some lines being the same.  File A :   command 1{     some code lines } command 2 command 3 command 4{     some code lines }   File B :  command 5 command 3 command 1{     some code lines }   I'd like to have a final file containing this:  command 1{     some code lines } command 2 command 3 command 4{     some code lines } command 5   Order of lines is not relevant. Is there an existing tool (or a command) to do so?
124287
I recently upgraded from Ubuntu 12.04 to 12.10 and at one point, it encountered an Apache config file conflict in apache2.conf. I didn't give me a merge option at that point, so I just rejected the new file and the installer saved the new file as apache2.conf.dpkg-dist.  I can diff the two files with diff apache2.conf apache2.conf.dpkg-dist and get just the lines that are different. But I want to manually merge the two sort of like how I resolve merge conflicts in SVN or git. How can I do that?
43435
I have two files, say file1.tex and file2.tex. file1.tex is the first of a series of files, and it begins with counters (say chapter 1 for instance, although my counters are not used for chapters). Then at the end of file1, the counter for chapters is at say 7 ; I want to carry the value of the counter to file2.tex so that I can use a counter which will have the value 7 in file2.tex. In this way I could possibly carry on the counter in file2.tex to a counter in some file3.tex and so on.   I assume I would need to compile file1.tex first, and then file2.tex, and then file3.tex... of course.  Is that possible? And if so, how? I couldn't think of anything.
86826
Objective: Merge the contents of two files using common key present in the files   file1.txt  =========  key1   11  key2   12  key3   13    file2.txt  =========  key2   22  key3   23  key4   24  key5   25    Expected Output :  ==================  key1   11  key2   12    22  key3   13    23   key4   24  key5   25   Approaches tried:   join command:  join -a 1 -a 2 file1.txt file2.txt ## full outer join  awk:  awk 'FNR==NR{a[$1]=$2;next;}{ print $0, a[$1]}' 2.txt 1.txt    Approach 2 is resulting in a right outer join and NOT a full outer join:     key1  11    key2  12    22    key3  13    23    What needs to be modified in approach 2 to result in a full outer join?
67450
I have a large file composed of text fields separated by semicolons in the form of a large table. It has been sorted. I have a smaller file composed of the same text fields. At some point, someone concatenated this file with others and then did a sort to form the large file described above. I would like to subtract the lines of the small file from the big one (i.e. for each line in the small file, if a matching string exists in the big file, delete that line in the big file).  The file looks roughly like this  GenericClass1; 1; 2; NA; 3; 4; GenericClass1; 5; 6; NA; 7; 8; GenericClass2; 1; 5; NA; 3; 8; GenericClass2; 2; 6; NA; 4; 1;   etc  Is there a quick classy way to do this or do I have to use awk?
101762
I have two files in these formats:   file1 :  air smell hand dude road cat   file 2:   air,4,21,01,13,3,2 smell,21,4,2,5,6 dude,1,31,42,1 road,1,4,2,1,4 cat,1,5,6,3,1 hand,1,4,2,1,6 mouse,1,3,5,6,2   what I want to do is print the entire row of file 2, if the first string in column 1 of file 2 is found in file 1, and I want to keep the order of file 1.   expected output:   air,4,21,01,13,3,2 smell,21,4,2,5,6 hand,1,4,2,1,6 dude,1,31,42,1 road,1,4,2,1,4 cat,1,5,6,3,1
33792
I have text file. Task - get first and last line from file after   $ cat file | grep -E "1|2|3|4" | commandtoprint  $ cat file 1 2 3 4 5   Need this without cat output (only 1 and 5).  ~$ cat file | tee &gt;(head -n 1) &gt;(wc -l) 1 2 3 4 5 5 1   Maybe awk and more shorter solution exist...
66374
I have two files.  file1:  Dave 734.838.9800   Bob 313.123.4567   Carol 248.344.5576   Mary 313.449.1390   Ted 248.496.2204   Alice 616.556.4458      file2:  Bob Tuesday   Carol Monday   Ted Sunday    Alice Wednesday   Dave Thursday     Mary Saturday     I merged the two files.  file3 should look like this:  Name      On-Call     Phone   Carol     MONDAY      248.344.5576   Bob       TUESDAY     313.123.4567   Alice     WEDNESDAY   616.556.4458   Dave      THURSDAY    734.838.9800   Nobody    FRIDAY      634.296.3356   Mary      SATURDAY    313.449.1390   Ted       SUNDAY      248.496.2204     But I cannot get the weekdays to be in order. How do I go about doing that?
48641
I need to split a .txt file into smaller ones containing 100 lines each, including the header. I don't know if this is relevant, but the original file is delimited like this:  COLUMN1 | COLUMN2 | COLUMN3 1 | 2 | 3 4 | 5 | 6 7 | 8 | 9   I need every file generated from this split to have the header line. Also, they need to be generated in/moved to another directory and follow a name pattern, like file_01.txt, file_02.txt, etc
61651
I have 2 big csv files, file1.csv which looks like this  1,2,3,4 1,4,5,6 1,7,8,9 1,11,13,17   file2.csv which looks like this  1,2,3,4 1,7,8,9 2,4,9,10 13,14,17,18   These are just random numbers that I made up, basically the two numbers where identical, and sorted. I want to compare file1.csv and file2.csv and then copy the rows that are present in file1.csv but not in file2.csv to file3.csv. the delimiter is comma obviously  I tried   comm -2 -3 file.csv file2.csv &gt; file3.csv   and I tried  diff -u file.csv file2.csv &gt;&gt; file3.csv   Both didn't work because file3 was bigger than file1 and file2. I tried different diff and comm commands, sometimes it's bigger than file2 and about the same size as file file1, I know that file3 has to be significantly  less in size than file1 and  file2. And of course I looked at file3, not the results I wanted  At this point, I know it could be done with diff or comm but I do not know the command to use.
113861
I have 2 text files. Lets name them file1.txt and file2.txt  file1.txt is as follows  chr10   181144  225933 chr10   181243  225933 chr10   181500  225933 chr10   226069  255828 chr10   255989  267134 chr10   255989  282777 chr10   267297  282777 chr10   282856  283524 chr10   283618  285377 chr10   285466  285995   file2.txt is as follows  chr10   181144  225933 chr10   181243  225933 chr10   181500  225933 chr10   255989  282777 chr10   267297  282777 chr10   282856  283524 chr10   375542  387138 chr10   386930  387138 chr10   387270  390748 chr10   390859  390938 chr10   391051  394580 chr10   394703  395270   What I want to output in a single file is    All the common lines between file1 and file2 All the lines which are in file1 but are not common to both All the lines which are in file2 but are not common to both.   I wrote a Perl script to do this but I am pretty sure there must be a command line or an easier way to do it.
58515
Lets say I got two files with a common field.  I want to sort the first one based on a field (eg. a numeric field) found in this file... but I want this re-ordering to apply to the other file as well - through the common field.  To take an example -- completely grabbed out of thin air ;-) -- lets take the /etc/passwd and /etc/shadow:   /etc/passwd: (...) sshd:x:124:65534::/var/run/sshd:/usr/sbin/nologin sndiod:x:999:29::/var/lib/sndiod:/usr/sbin/nologin dictd:x:125:135:Dictd Server,,,:/var/lib/dictd:/bin/false postgres:x:126:136:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash (...)    /etc/shadow: (...) sshd:*:17055:0:99999:7::: sndiod:!:17055:::::: dictd:*:17055:0:99999:7::: postgres:*:17055:0:99999:7::: (...)   Sorting /etc/passwd numerically on UID is easy enough:  sort -n -t: -k3 /etc/passwd &gt; pw  Which with the lines above yields:   /etc/passwd: (...) sshd:x:124:65534::/var/run/sshd:/usr/sbin/nologin dictd:x:125:135:Dictd Server,,,:/var/lib/dictd:/bin/false postgres:x:126:136:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash sndiod:x:999:29::/var/lib/sndiod:/usr/sbin/nologin (...)   However, /etc/shadow does not have a numeric UID-field I can sort after... It does however -- like /etc/passwd -- got a username-field...    So is there a way to re-order the lines in /etc/shadow so that the username-field had the same order as the username-field in the numerically sorted /etc/passwd?   Is there a command -- sort or something similar -- which can sort file A after some key in that file, and simultaneously sort file B on a common field shared by both files? Alternatively, is there a suitable two-step-process -- a command, a sed/AWK/Perl-script, or something -- that can use the sorted file A to re-order file B after their common field?
112069
I have multiple files with the same header and different vectors below that. I need to concatenate all of them but I want only the header of first file to be concatenated and I don't want other headers to be concatenated since they are all same.   for example: file1.txt  &lt;header&gt;INFO=&lt;ID=DP,Number=1,Type=Integer&gt; &lt;header&gt;INFO=&lt;ID=DP4,Number=4,Type=Integer&gt; A B  C   file2.txt  &lt;header&gt;INFO=&lt;ID=DP,Number=1,Type=Integer&gt; &lt;header&gt;INFO=&lt;ID=DP4,Number=4,Type=Integer&gt; D E  F   I need the output to be   &lt;header&gt;INFO=&lt;ID=DP,Number=1,Type=Integer&gt; &lt;header&gt;INFO=&lt;ID=DP4,Number=4,Type=Integer&gt; A B C D E  F   I could write a script in R but I need it in shell?
39034
I have two files A and B.  I want to find out which lines of file B are not present in the file A.   How do I do this? The lines can be at any position in file A
15745
I want to replace the 5th line of multiple text files (file1.txt,file2.txt,file3.txt,file4.txt) with the string " Good Morning " using a single terminal command.  All the text files are located on my ~/Desktop.  Note: My desktop consists of 6 .txt files.I want to apply the change to above mentioned 4 text files only.
56033
So I have a file text.txt  with lines of some characters example:  abc     abc yxz abc   now I would like to number the lines like this and copy it to another file.  End expected result:  1  abc 2  abc  3  yxz 4  abc
15133
If I have a file with contents similar to:  FirstSection     Unique first line in first section     Unique second line in first section  SecondSection     Unique first line in second section     Unique second line in second section  ...  NthSection     Unique first line in Nth section     Unique second line in Nth section   Is it possible to use unix commands (e.g. sort, awk) to sort the file alphabetically by the first non-indented line in each three line group, whilst keeping the indented lines under their existing group?
93093
I have a file with this content: $ cat compromised_header.txt some unique string 1 some other unique string 2 another unique string 3  I wanted to find all files that have all the lines of above file exactly in the same order and those lines have no intermediary lines in between. Example input file: $ cat a-compromised-file.txt some unique string 1 some other unique string 2 another unique string 3 unrelated line x unrelated line y unrelated line z  I tried using below grep: grep -rlf compromised_header.txt dir/  But I wasn't sure it will give the expected files as it will also match this file: some unique string 1 unrelated line x unrelated line y unrelated line z