How do I pick a random row of text from a file?
122850
Is there any Linux command one can use to sample subset of a file? For instance, a file contains one million lines, and we want to randomly sample only one thousand lines from that file.   For random I mean that every line gets the same probability to be chosen and none of the lines chosen are repetitive.  head and tail can pick a subset of the file but not randomly. I know I can always write a python script to do so but just wondering is there a command for this usage.
80769
Lets say I'm doing a database for fruits. Using a text file for it, inside contains, in this format,  (Fruit:Quantity:Cost) Apple:10:1 Orange:20:2 Pears:10:3 Banana:20:4  10 Apples at $1 each. 20 Oranges at $2 each. 10 Pears at $3 each. 20 Bananas at $4 each.   My simple script goes like this:  echo "Enter fruit to find" read fruit  echo "Enter quantity to find" read count  echo "Enter cost to find" read cost  grep $fruit FruitDB.txt     It will display the fruits in the database.  But how do i use grep and cut together to find just by the quantity or the cost. In the quantity count area, let's say i enter 20, it will display the Oranges and Banana. Or when i enter count and cost, it will display just those that meet the conditions.
9614
Is there any way to create a text file without using the terminal at all?
1748
I have a data like this:  input.txt  1 0000100101000000 1 0000010100000000 2 1110000001000000 2 1111000000001000 3 0000000111111111 3 1111111100000000 4 8888345500000000 4 0000000000000000   and I want to sum up the values within eachtwo rows with the same row number: output:  output.txt  1 0000110201000000 2 2221000001001000 3 1111111211111111 4 8888345500000000   any suggestion please? my real dat had 8000 rows with 45000 digit in each line
82128
NOTE: This question is the complement of this Q&amp;A:     I need to get only the lines from a textfile (a wordlist, separated with newline) that has a length range of minimum or equal than 3 characters, but not longer or equal than 10.   Example:   INPUT:   egyezményét megkíván ki alma kevesen meghatározó   OUTPUT:   megkíván alma kevesen   Question: How can I do this in bash?
116435
I have a text file that looks like his:  #c1     c2              c3              c4              c5              c6      c7      c8      c9      c10     c11     c12     c13 4599    995,274 2523,658        264,1417170     -33,6000        -0,3600 0,0202  0,0069  0,0227  10,1041 0,0169  0,2817  0,0239 6173    1552,290        1595,696        264,0603912     -33,4880        0,4374  0,0287  1,8123  0,0385  10,1289 0,0292  2,8445  0,0366 6456    1658,630        1529,292        264,0449377     -33,4800        0,0109  0,0234  1,0955  0,0296  10,5032 0,0223  1,7168  0,0293 8932    2750,029        1374,395        263,8866195     -33,4615        -0,3185 0,0249  0,9196  0,0302  10,5858 0,0221  1,3886  0,0296 4095    820,716 495,315 264,1658451     -33,3546        -0,4388 0,0216  0,6497  0,0252  10,6026 0,0188  1,1796  0,0258 4737    1045,289        1395,983        264,1338240     -33,4636        0,5900  0,0231  0,8853  0,0273  10,6501 0,0204  1,1661  0,0270   ie: not aligned at certain random lines (the file is ~10000 lines long) I need it to look like this:  #c1     c2              c3              c4              c5              c6      c7      c8      c9      c10     c11     c12     c13 4599    995,274         2523,658        264,1417170     -33,6000        -0,3600 0,0202  0,0069  0,0227  10,1041 0,0169  0,2817  0,0239 6173    1552,290        1595,696        264,0603912     -33,4880        0,4374  0,0287  1,8123  0,0385  10,1289 0,0292  2,8445  0,0366 6456    1658,630        1529,292        264,0449377     -33,4800        0,0109  0,0234  1,0955  0,0296  10,5032 0,0223  1,7168  0,0293 8932    2750,029        1374,395        263,8866195     -33,4615        -0,3185 0,0249  0,9196  0,0302  10,5858 0,0221  1,3886  0,0296 4095    820,716         495,315         264,1658451     -33,3546        -0,4388 0,0216  0,6497  0,0252  10,6026 0,0188  1,1796  0,0258 4737    1045,289        1395,983        264,1338240     -33,4636        0,5900  0,0231  0,8853  0,0273  10,6501 0,0204  1,1661  0,0270   So basically I'm looking for a script/command line utility to automatically align the columns of the file.
45384
If I use cat -n text.txt to automatically number the lines, how do I then use the command to show only certain numbered lines.
3334
I am writing a batch file script using Windows command-line environment and want to change each occurrence of some text in a file (ex. "FOO") with another (ex. "BAR"). What is the simplest way to do that? Any built in functions?
82405
I have a text file where I want to change only the first line of the file.  The file could be millions of rows long, so I'd rather not have to loop over everything, so I'm wondering if there is another way to do this.  I'd also like to apply some rules to the first line so that I replace instances of certain words with other words.  Is this possible?
112590
How do I get from this:  randomcollege-nt\user90   to this:  user90   using sed?
96495
Document 1 has many rows of data.  How do I import into document 2 only those rows that have a certain value in column C?
89658
I have a wordlist that I'd like to extract every line of text from that contains only numbers, to a new file.  What do I do?
75502
I have a tabular file in which the first column has IDs and the second one has numeric values. I need to generate a file that contains only the line with the largest score for each ID.  So, I want to take this:  ES.001      2.33 ES.001      1.39 ES.001    119.55 ES.001     14.55 ES.073      0.35 ES.073     17.95 ES.140      1.14 ES.140     53.88 ES.140     18.28 ES.178    150.27   And generate this:  ES.001    119.55 ES.073     17.95 ES.140     53.88 ES.178    150.27   Is there a way of doing this from a bash command-line?
19728
How do I select one or more random rows from a table using SQLAlchemy?
9019
What's a good way of extracting say, lines 20 -45 out of a huge text file. Non-interactively of course!
68825
I am analyzing a file xyz.txt which contains hifen separated records. I want to extract records based on the presence of the strings FADED:100,  AM:FF and GG. Subsequently, I need to write them to a new file, faded100.txt. The source file include more then 40 thousand records, looking like below.   --- --------  --- -- -- -- -- -- -- -- -- -- -- -- -- -- --  --- --- -- --      rtuyss  A/A go go go go go go go go go go go go go go  IRE AP  QQ Z ORDER xxxxxxx1  country: 201  NVDS        TEMPROR   EXTREME  BUS TIME:       TRASS: 12       AIDED: 12        FADED: 100                        U  U  U  u  U  A  U  O  O  O  O  O  O  O                  GG   Y  Y  Y  Y  Y  O  Y  O  O  O  O  O  O  O   POU ATM UNITED #  AM:FF   Y  Y  Y  Y  Y  O  Y  O  O  O  O  O  O  O   POU POU POU POU --- --------  --- -- -- -- -- -- -- -- -- -- -- -- -- -- --  --- --- -- --  rtuyss  A/A go go go go go go go go go go go go go go  IRE AP  QQ Z ORDER xxxxxxx1  country: 201  NVDS        TEMPROR   EXTREME  BUS TIME:       TRASS: 12       AIDED: 12        FADED: 200                        U  U  U  u  U  A  U  O  O  O  O  O  O  O                   ZZ  Y  Y  Y  Y  Y  O  Y  O  O  O  O  O  O  O   POU ATM UNITED #   AM:FF  Y  Y  Y  Y  Y  O  Y  O  O  O  O  O  O  O   POU POU POU POU  --- --------  --- -- -- -- -- -- -- -- -- -- -- -- -- -- --  --- --- -- --  rtuyss  A/A go go go go go go go go go go go go go go  IRE AP  QQ Z ORDER xxxxxxx1  country: 201  NVDS        TEMPROR   EXTREME  BUS TIME:       TRASS: 12       AIDED: 12        FADED: 100                       U  U  U  u  U  A  U  O  O  O  O  O  O  O                   IP Y  Y  Y  Y  Y  O  Y  O  O  O  O  O  O  O   POU ATM UNITED #   AM:FF Y  Y  Y  Y  Y  O  Y  O  O  O  O  O  O  O   POU POU POU POU  --- --------  --- -- -- -- -- -- -- -- -- -- -- -- -- -- --  --- --- -- --
3386
Is there a function to extract the extension from a filename?