Tag Info

New answers tagged

0

With zsh: files=(/var/abc/*.csv(N.)) n=0 while (($#files)) { cat $files[1,1000] > file$((++n)).csv && rm -f $files[1,1000] || break files[1,1000]=() }


1

Your command looks almost fine. Just add a cat and >> to actually append the content: for i in /var/abc/*.csv; do cat "$i" >> file1.csv && rm -rf "$i";done I don't quite understand the counting part. You could do something like this: let count=0 for i in /var/abc/*.csv; do cat "$i" >> file1.csv && rm -rf "$i" let ...


5

You don't need to loop, you can tell cat to read all the files: cat /var/abc/*.csv > file1.csv && rm /var/abc/*.csv as long as there aren't too many files (but the limit is huge). Using && between the two commands ensures the files are only deleted if they were successfully "copied". There are a couple of caveats though: you mustn't ...


1

You would almost think that you invented the syntax for GNU Parallel: ... | parallel -N5 curl www.google.com/{1}/testing/{2}/{3}/works/{5} You get the added benefit that you will be running one curl per CPU. GNU Parallel is a general parallelizer and makes is easy to run jobs in parallel on the same machine or on multiple machines you have ssh access ...


14

Characters of code 0 to 31 in ASCII are control characters. When sent to a terminal, they're used to do special things. For instance, \a (BEL, 0x7) rings the terminal's bell. \b (BS, 0x8) moves the cursor backward. \n (LF, 0xa) moves the cursor one row down, \t (TAB 0x9) moves the cursor to the next tabulation... \r (CR, 0xd) moves the cursor to the first ...


5

\x0d is the character \r which brings the cursor to the start of the line, then \x20 is a space, so it overwrites the a with a space. If you're on a unix-y system you may want to consider just removing \r from your output/file since it's not needed if it's for text output. The \n "implies" it for *nix, but not for Windows.


2

That has nothing to do with cat, pipes or buffering. Your "problem" is upstreams, at the terminal device. If every character you enter at the keyboard in the terminal was available for reading by your application immediately and cat, then would you enter aBackspacebReturn, your application would read a then ^? then b then ^M, which is not what you want and ...


-2

follow this loop: while((ch=getchar())!=EOF) { write(p[1],&ch,1); } with: char carriageReturn = 0x0D; write( p[1], &carriageReturn, 1 );


0

I use vimcat. https://github.com/ofavre/vimcat It looks good enough for me.


0

There is no need to set the field separator to any special value such as "=". By default, AWK uses contiguous spaces and tabs as field separators, which are skipped, so it will interpret each line of your file as having three fields, without any leading space on field three awk '/^email2/ { print $3 }' produces user@winkum.worg The above would also ...


2

perl -nlE 's/email2\s*=\s*// and say' file Where: perl -nl is a for each line do... s/email2 = // removes the searched email id and if you could do it ... say prints the current input input line \s* zero or more spaces (equivalent to [ \t\n]*)


3

The exact equivalent would be something like: sed -n '/email2/{s/^[^=]*=\([^=]*\).*/\1/;p;}' < file But you'd probably want instead: sed -n 's/^[^=]*email2[^=]*=[[:blank:]]*//p' < file (that is match email2 only on the part before the first = and return everything on the right of the first = (skipping leading blanks), not only the part up to the ...


2

How about using awk? awk -F = '/email2/ { print $2}' /etc/emails.conf -F = => Fields are separated by '=' '/email2/ { print $2}' => on lines that match "email2" print the second field


0

You can use <<< to simply read from the variable containing the newline-separated data: while read -r line do echo "A line of input: $line" done <<<"$lines"


1

@Costas - good answer! And since they're sh scripts, sh /home/german/prueba.txt will work, as well. And, BTW, this was supposed to be a comment (isn't that what Add Comment is supposed to do?)



Top 50 recent answers are included