I want to extract an exact line from a very big file. For example, line 8000 would be gotten like this:  command -line 8000 &gt; output_line_8000.txt
31561
Say I have a huge text file (>2GB) and I just want to cat the lines X to Y (e.g. 57890000 to 57890010).  From what I understand I can do this by piping head into tail or viceversa, i.e.   head -A /path/to/file | tail -B   or alternatively  tail -C /path/to/file | head -D   where A,B,C and D can be computed from the number of lines in the file, X and Y.  But there are two problems with this approach:   You have to compute A,B,C and D. The commands could pipe to each other many more lines than I am interested in reading (e.g. if I am reading just a few lines in the middle of a huge file)   Is there a way to have the shell just work with and output the lines I want? (while providing only X and Y)?
18367
In a file with lots of lines I want to delete lines that starts with HERE IT IS.  How can I do this using only command-line tools?
85410
Below is the text in the file:  Pseudo name=Apple Code=42B state=fault  Pseudo name=Prance Code=43B state=good   I need to grep for "42B" and get the output from the above text like:   Pseudo name=Apple Code=42B state=fault   Does anyone have idea on how to achieve this using grep/awk/sed?
26898
I have this script to divide a file over a 100000 or even more in 50000 lines.  desc()                                                     {                                                       echo $1 $2|awk '{d=$1;}                                 BEGIN {a=1;b=0}                                            { f=d"0"a;                                                while ((getline x&lt;d)&gt;0)                                   { print x&gt;&gt;f".txt"                                        if (b++&gt;=50000)                                            {                                                         close(f);b=0;a++;f=(a&lt;10)?d"0"a:f=d""a                }                                                  }                                                   }                                                   END {print "Terminado ... ! "}'                         }                                                      if [ -f $1 ]; then                                              desc $1 $2                                      fi                                                        When I execute it I got this error message:  sh-3.2$ parte.sh pa.txt                                  : command not found                                      '/parte.sh: line 2: syntax error near unexpected token ` '/parte.sh: line 2: `desc()                              sh-3.2$                                                    Can anyone help to solve it?
109159
I have a file with the following contents:  select *  from  emp;   select *  from  dept;  selection end;   I want to obtain this output:  select *  from  emp;   select *  from  dept;   I tried by using   awk '/SELECT/{a=1} a; /;/{a=0}' XXARXADLMT.txt    But it didn't work.
44782
I want to terminate the tail command after having the match found and until then all the lines are written to another file. tail -f logfile | sed '/special string/q'  | tee output.txt  Output.txt will have the lines until special string is found. But the problem is, after that I want to end the tail command.
8107
How can you you insert a newline from your batch file output?  I want to do something like:  echo hello\nworld   Which would output:  hello world
104026
I'm sure I once found a unix command which could print the common lines from two or more files, does anyone know its name? It was much simpler than diff.
96496
I created a script ./abc.  I want to break the ouput into new lines.  mycode:  #!/bin/bash dir="$1"  echo -n "size of file:" du -hba $dir | sort -n -r | tail -1   my output is:   size of files: 20kb /path/to/sport   I want the output as:  size of files: 20kb          /path/to/sport
33496
I have a script that outputs text to stdout. I want to see all this output in my terminal, and at the same time I want to filter some lines and save them in a file. Example:  $ myscript Line A Line B Line C  $ myscript | grep -P 'A|C' &gt; out.file  $ cat out.file Line A Line C   I want to see output of first command in terminal, and save the output of the second command in a file. At the same time. I tried using tee, but with no result, or better, with .
97947
I’m taking two input files, one with certain ID numbers, and another with a large list of ID numbers and additional columns. The latter file contains multiple lines for each ID number and I need to extract all lines that match an ID from the first file. Those lines then must be printed in a new file.  Edit 1: Replaced sample files with excerpts from actual  Edit 2: Removed extra spaces that were in excerpt, but not actual file. Files likely need to be sanitized in some way, but how is unclear.  file1:  AT1G56430 AT3G55190 AT3G22880   file2:  AT1G01010|GO:0043090|RCA AT1G56430|GO:0010233|IGI  AT1G56430|GO:0009555|IGI  AT1G56430|GO:0030418|IGI   expected output  AT1G56430|GO:0010233|IGI  AT1G56430|GO:0009555|IGI  AT1G56430|GO:0030418|IGI   [[  I have tried:  awk -F'|' 'NR==FNR{c[$1$2]++;next};c[$1$2] &gt; 0' file1 file2 &gt; output.txt   and:  grep -Ff file2 file1 &gt; output.txt   I’m aware that there are many somewhat similar questions posted in these forums and others. However, these don’t mention how the output is handled… nor do they mention duplicates. I’ve tried solutions from 4 of them, have been messing with this for many hours and keep getting the same problem: a blank output file.   I’m new to awk and I greatly appreciate the help. Sorry if this is a simple problem with syntax etc; please let me know. Thanks for the help.
11784
I want to start grepping from the lines that has CK at the end of line and stop grepping when the line has D at the end. I tried grep "$CK" "$D" file..txt, but it didn't work.  Input:  kkkkkkkkkkk    jjjjjjjjjjjjjjjjjj   gggggggggggg/CK   JHGHHHHHHHH    HJKHKKLKLLL    JNBHBHJKJJLKKL   JLKKKLLKJLKJ/D   GGGGGGGGGGGGGG   GGGGGGGGGGGGGG   The desired output:  gggggggggggg/CK   JHGHHHHHHHH    HJKHKKLKLLL    JNBHBHJKJJLKKL   JLKKKLLKJLKJ/D
70438
I want to be able to capture the exact output of a command substitution, including the trailing new line characters.  I realise that they are stripped by default, so some manipulation may be required to keep them, and I want to keep the original exit code.  For example, given a command with a variable number of trailing newlines and exit code:  f(){ for i in $(seq "$((RANDOM % 3))"); do echo; done; return $((RANDOM % 256));} export -f f   I want to run something like:  exact_output f   And have the output be:  Output: $'\n\n' Exit: 5   I'm interested in both bash and POSIX sh.
87030
I am doing grep and sed and I get 2 lines of a file that I am interested in. How can I get these lines in a single line ending with the new line character? Now I am getting:    pattern1   pattern2     I would like to get pattern1 pattern2 \n
58499
I have a large JSON file that is on one line, and I want to use the command line to be able to count the number of occurrences of a word in the file. How can I do that?
1865
I have some text files, and I'd like to be able to move an arbitrary line in any of the files up or down one line (lines at the beginning or end of the file would stay where they are).  I have some working code but it seems kludgy and I'm not convinced I have all the edge cases covered, so I'm wondering if there's some tool or paradigm that does this better (e.g. easier to understand the code (for other readers or me in 6 months), easier to debug, and easier to maintain; "more efficient" isn't very important).  move_up() {   # fetch line with head -&lt;line number&gt; | tail -1   # insert that one line higher   # delete the old line   sed -i -e "$((line_number-1))i$(head -$line_number $file | tail -1)" -e "${line_number}d" "$file" }  move_down() {   file_length=$(wc -l &lt; "$file")   if [[ "$line_number" -ge $((file_length - 1)) ]]; then     # sed can't insert past the end of the file, so append the line     # then delete the old line     echo $(head -$line_number "$file" | tail -1) &gt;&gt; "$file"     sed -i "${line_number}d" "$file"   else     # get the line, and insert it after the next line, and delete the original     sed -i -e "$((line_number+2))i$(head -$line_number $file | tail -1)" -e "${line_number}d" "$file"   fi }   I can do error checking of inputs inside or outside these functions, but bonus points if bad input (like non-integers, non-existent files, or line numbers greater than the length of the file) are handled sanely.  I want it to run in a Bash script on modern Debian/Ubuntu systems.  I don't always have root access but can expect "standard" tools to be installed (think a shared web server), and may be able to request installation of other tools if I can justify the request (though fewer external dependencies is always better).  Example:  $ cat b 1 2 3 4 $ file=b line_number=3 move_up $ cat b 1 3 2 4 $ file=b line_number=3 move_down $ cat b 1 3 4 2 $
84318
Let's say I have a text file like:  john george james stewert   with every name on a separate line.  I want to read the lines of this text file and create a text file for each name, like: john.txt, george.txt etc.  How can I do this in Bash?