You can use sleep
and clear
commands in your script as following:
for word in $(< read)
do
echo "$word"
sleep 1
clear
done
Explanation:
The sleep
command make delay for a specified amount of time (in seconds). With sleep 1
delay would be for 1 second. You can change for more time delay by incrementing the second parameter or for delaying less than 1 second divide it to low units; Like sleep .1
for 1/10 second delay or sleep .001
for 1/1000 second delay and etc.
The clear
command clear the terminal screen.
Even better you can do this through below awk
command:
awk '{i=1; while(i<=NF){ print $((i++)); system("sleep 1; clear") }}' read
Explanation:
In awk
, the NF
specifies the total number of fields in the current input record/line, so by using a variable as a counter (i
) and looping over it, we are printing all of them from 1st position to the end of them (NF
). Then by using the system("sleep 1; clear")
part, we are telling to awk
to calling the system commands to sleeping for 1 second and clearing the screen.
In above we are displaying the input file as word by word. If you are going to display it line by line add IFS=$'\n'
in the script like:
IFS=$'\n'
for word in $(< read)
do
echo "$word"
sleep 1
clear
done
And change the awk
command like:
awk '{ $0; system("sleep 1; clear") }1' read
$0
specifies the current line. and the 1
on end enables the default awk
's print command.
Use head
:
head -n1 -q *.txt > new-file
-n1
tells head
to extract the first line only.
-q
tells head not to print the filename.
On OS X (and probably on some other *nix variants) the -q
option is not supported by head
. You need to remove the filenames yourself, e.g.
head -n1 *.txt | grep -v '==> ' > new-file
This only works if you know the output shouldn't contain the ==>
string. To be absolutely sure, use a loop (which will be much slower than running head
just once):
for file in *.txt ; do
head -n1 "$file"
done
Best Answer
With the
cut
tool you can limit the output to 100. Since you only interested in thecharacters
hence the columns they occupy this should do that nicely:In case you wish to remove the spaces in there this would help:
See:
man cut
Using
awk
:Getting rid of spaces again if required:
AWK:
gsub (" ", "", $0)
: find" "
(spaces) and replace with""
globally in target string$0
.substr( $0, 0, 100 )
: it returns 100 number of chars from string $0, starting at position 0.