Command Output To File On The Same Line

I know that '>' and '>>' will redirect output to a file

However, how does one keep this output on the same line as the previous line?

'echo -n' will stop a trailing new line but for terminal redirection?


Similar Content



What Do I Do With This Huge Data On My Command Line Interface

Hi,

I have been trying to get information on how to process the output of a tcl file (aodv and leach protocol using mannasim) which I got on my command line Iinterface. Actually, I don't even know the keywords to search as I am new to this and other minor attempts haven't yielded positive results., I know there is usually a trace file but I can't see any. All I see is on my command line.

I also observe that it took the space on the entire screen and I can't copy the output from the start ( I could only copy from node 19 out of 30 nodes) because of the huge number of output lines.

The last thing I havent been able to figure ou is whether temperature is equivalent to energy Iin mannasim as mannasim has only temperature and carbon dioxide?


Thanks

How To Redirect The Error Message?

I have a hostlist and there are several hosts. I want to use ssh to connect to them. I want to see whether the host is available or not by the time length of ssh takes. If it take long than 5s (which means it is not available). Then stop it, and ssh to next host. Once a host is available, then output the name of host. I previously use nmap, but the IT security told it is not allowed to install it on the desktop on campus.
Code:
    HOSTS=`cat $host_list`
    for line in $HOSTS
    do 
    ssh -o ConnectTimeout=5s $line true >> /dev/null
    RESULT=$?
    if [ $RESULT -eq 0 ]
    then
    echo $line > succeed.txt
    else
    echo $line > fail.txt
    fi
    done

The above script is all I can do.
The problem is when it is failed, I want to redirect the error message
Code:
ssh: connect to host c28-0112-05.ad.mtu.edu port 22: No route to host

. But I still get the error message.

Stdout, Stderr And Redirection -- What Is The Correct Order Or Format ?

Hi all,

Been reading on stdin, stdout and stderr and encounter 2 questions, hope gurus here can advise.

0 = stdin
1 = stdout
2 = stderr

Code:
Sun Dec 21 03:53:42 SGT 2014 > cat test5.sh
#!/bin/bash

echo "Please enter value for name :"
read name
echo "Your name is $name."

echo "Next echo will be a syntax error"
ehco

Code:
Sun Dec 21 03:53:46 SGT 2014 > test5.sh 1> output.txt 2> error.txt
Noob

Sun Dec 21 03:54:56 SGT 2014 > cat output.txt
Please enter value for name :
Your name is Noob.
Next echo will be a syntax error

Sun Dec 21 03:55:23 SGT 2014 > cat error.txt
/home/alan/scripts/test5.sh: line 8: ehco: command not found
Sun Dec 21 03:55:26 SGT 2014 >

Which so far all is good and the correct way to output everything including error to a single file is

Code:
Sun Dec 21 03:59:14 SGT 2014 > test5.sh > output.txt 2>&1


Q1) How is a command being interpreted in linux , the sequence in which it is interpreted ? from left to right ? right to left ?

Shouldn't it be

Code:
test5.sh 2>&1 1>output.txt 
or 
test5.sh 2>&1>output.txt ?

Regards,
Noob

Search For A Character In Specific Word In File And Replace It In The Word

Hi all ,
I have a requirement where I have a file. Contents of the file are :
#comments
VAR="abg"
RES=123
#comments
IC6790ABG="https://www.abc.com"
IC5678-vg="https://www.bhy.com"
IC-gy_567:78="https://www.gyt.com"
#comments
The variable names can not have characters like - , : so
in this file I have to find words starting with IC and replace characters like - ,:
I want to change only the variable name , not the whole line.
I have used SED command

sed -i '/^IC/s/[^0-9 a-z A-Z _]*//g' file

when I am using this command , it is replacing the whole line
output becomes :

#comments
VAR="abg"
RES=123
#comments
IC6790ABGhttpswwwabccom
IC5678vghttpswwwbhycom
ICgy56778httpswwwgytcom
#comments


But I want the output like this :

#comments
VAR="abg"
RES=123
#comments
IC6790ABG="https://www.abc.com"
IC5678vg="https://www.bhy.com"
ICgy_56778="https://www.gyt.com"
#comments

How can I get the desired output , thanks for your help in advance .

Checking Presence Of A File Identified/ Addressed By A Variable

hi,

I am newbie in Linux shell scripting.Can anybody help me to check the presence of file identified by variable in Shell scripting?

For example: I am reading the content of a file using while command as below:
"while read -r line
do
code block
done < file_name"

Now in this case every line in file gets stored in the variable 'line' one by one.Problem here is every line in the file is nothing but the file_path of another file say xyz.txt and I am checking presence of this xyz.txt file using below command:
if [-f $line]
as 'line' is the variable which stores file path of xyz.txt but it is not working. It is unable to check the presence of this xyz.txt file as i am addressing it with the variable 'line'.

Please help me.Thanks in advance.

Remove Lines That Are Subsets Of Other Lines In File

Hello everyone,


Although it seems easy, I've been stuck with this problem for a moment now and I can't figure out a way to get it done.

My problem is the following:

I have a file where each line is a sequence of IP addresses, example :

Line 1: 10.0.01 10.0.0.2
Line 2 : 10.0.0.5 10.0.0.1 10.0.0.2
...

What I'd like to do, is to remove lines that are completely matched in other lines. In the previous example, "Line 1" would be deleted as it is contained in "Line 2".

So far, I've worked with python and set() objects to get the job done but I've got more than 100K lines and sets lookups are becoming time consuming as the program goes :/

Thanks for you help

Bash Script To Output Certain Lines From A File

I am trying to write a script to create a variable (string) out of specific lines from another file. The string will be used as headings for lists in another script. My plan is to create a variable "myvar" with the output from an awk command run against a file called banners.txt then I can call $myvar whenever it is appropriate in the larger script. additionally I can add/modify the banner file instead of having to comb through a large script to add or change echo commands.
So, here is my proof of concept script:
Code:
#!/bin/bash

path=/home/rstenger/

TESTFILE=$(<banners.txt)
MYVAR=$( awk 'NR > 6 && NR < 10' "$TESTFILE" )
#
echo ""
echo ""
echo $MYVAR
#
for i in {1..5}; do echo ""; done
echo $TESTFILE

exit

which produces this output:
Code:
sl7jump1~#->./test1.sh 
awk: cmd. line:2: fatal: cannot open file `******************************************************
*                1st banner has 3 line               *
******************************************************
******************************************************
*                2nd banner has 3 line               *
****************************************************** 
******************************************************
*                3rd banner has 3 line               *
******************************************************' for reading (File name too long)








3rd_floor_lab_ex3200s.txt banner banners.txt ban_test.sh base_configs Images lab_cyclades.sh lab_devices.v3.sh Projects savvis.lab_device_list Savvis_Lab-Domain-DNS.txt test1.sh vrf_names 3rd_floor_lab_ex3200s.txt banner banners.txt ban_test.sh base_configs Images lab_cyclades.sh lab_devices.v3.sh Projects savvis.lab_device_list Savvis_Lab-Domain-DNS.txt test1.sh vrf_names 1st banner has 3 line 3rd_floor_lab_ex3200s.txt banner banners.txt ban_test.sh base_configs Images lab_cyclades.sh lab_devices.v3.sh Projects savvis.lab_device_list Savvis_Lab-Domain-DNS.txt test1.sh vrf_names 3rd_floor_lab_ex3200s.txt banner banners.txt ban_test.sh base_configs Images lab_cyclades.sh lab_devices.v3.sh Projects savvis.lab_device_list Savvis_Lab-Domain-DNS.txt test1.sh vrf_names 3rd_floor_lab_ex3200s.txt banner banners.txt ban_test.sh base_configs Images lab_cyclades.sh lab_devices.v3.sh Projects savvis.lab_device_list Savvis_Lab-Domain-DNS.txt test1.sh vrf_names 3rd_floor_lab_ex3200s.txt banner banners.txt ban_test.sh base_configs Images lab_cyclades.sh lab_devices.v3.sh Projects savvis.lab_device_list Savvis_Lab-Domain-DNS.txt test1.sh vrf_names 2nd banner has 3 line 3rd_floor_lab_ex3200s.txt banner banners.txt ban_test.sh base_configs Images lab_cyclades.sh lab_devices.v3.sh Projects savvis.lab_device_list Savvis_Lab-Domain-DNS.txt test1.sh vrf_names 3rd_floor_lab_ex3200s.txt banner banners.txt ban_test.sh base_configs Images lab_cyclades.sh lab_devices.v3.sh Projects savvis.lab_device_list Savvis_Lab-Domain-DNS.txt test1.sh vrf_names 3rd_floor_lab_ex3200s.txt banner banners.txt ban_test.sh base_configs Images lab_cyclades.sh lab_devices.v3.sh Projects savvis.lab_device_list Savvis_Lab-Domain-DNS.txt test1.sh vrf_names 3rd_floor_lab_ex3200s.txt banner banners.txt ban_test.sh base_configs Images lab_cyclades.sh lab_devices.v3.sh Projects savvis.lab_device_list Savvis_Lab-Domain-DNS.txt test1.sh vrf_names 3rd banner has 3 line 3rd_floor_lab_ex3200s.txt banner banners.txt ban_test.sh base_configs Images lab_cyclades.sh lab_devices.v3.sh Projects savvis.lab_device_list Savvis_Lab-Domain-DNS.txt test1.sh vrf_names 3rd_floor_lab_ex3200s.txt banner banners.txt ban_test.sh base_configs Images lab_cyclades.sh lab_devices.v3.sh Projects savvis.lab_device_list Savvis_Lab-Domain-DNS.txt test1.sh vrf_names

What I was looking for is:
Code:
******************************************************
*                3rd banner has 3 line               *
******************************************************

I am very puzzled as to why I get the contents of the file in the awk error message, and the contents of my home directory as the variable.

Thanks,
Robert

Need Help In Bash Scripting

I have two files which has exact same number of lines.
I want first line of first file should be filename of new file and content of this new file should be first line of second file.
Then second line of first file should be filename of again new file and content of this new file should be second line of second file.
then third line of first file should be filename of again new file and content of this new file should be third line of second file.
and so on...
I am trying to do it using for loop but I am not able to create two for loops.
This is what I have done
Code:
IFS=$'\n'
var=$(sed 's/\"http\(.*\)\/\(.*\).wav\"\,\".*/\2/g' 1797.csv) # filenames of all files
var2=$(sed 's/\"http\(.*\)\/\(.*\).wav\"\,\"\(.*\)\"$/\3/g' 1797.csv) # contents of all files
for j in $var;
do
#Here I do not know how to use $var2
done

Please help.

Extract Middle Of File - How To Strip Header/footer

I have a log file with a header (which I can skip with awk), and a footer, which I need to find a way to remove. The goal is to extract the middle lines from a file. Specifically, there is a header (1 line) and a footer (1 line).
The only way I can figure out how to do this is if I already know how many lines are in the file to begin with. For example, if the file looks like this: line 1 (header)
line 2 (interesting line)
line 3 (interesting line)
line 4 (footer)
I just want to extract the middle "interesting lines" without the header/footer lines.
I can't use grep to remove the header/footer, because I don't know what those lines will contain, only that they exist and are exactly 1 line each. In general, I don't know how many lines are in the file.

Executing Command From File (with Tail) Probably Misquotes?

When working with a virtual terminal, I find it often easier to edit a file to execute than to construct a regular-expression etc. to inject the right UUID etc. into the command. I have run into an error while doing this. I suspect it is stems from quote mishandling, or improper escape sequences. (I ran directly from the command line earlier, forgot a quotation mark, and it gave a similar bad result.)
The program in question was efibootmgr. I had a file vaguely similar to this one, named efiboot.Hz:
Code:
efibootmgr -c -g -L "Debian (EFI stub)" -l '\EFI\debian\vmlinuz' -u 'root=UUID=$UUID ro quiet rootfstype=ext4 add_efi_memmap initrd=\\EFI\\debian\\initrd.img'
efibootmgr -c -d /dev/sdb -L "Debian Linux" -l '\EFI\debian\vmlinuz' -u 'root=UUID=1234-ffff-789 ro quiet rootfstype=ext4 add_efi_memmap initrd=\\EFI\\debian\\initrd.img'

Then I executed:
Code:
`tail -n 1 efiboot.Hz`

efibootmgr -v revealed the previous command produced a garbled name and boot options, and most importantly it didn't boot. Manually writing the last line on the terminal did produce the desired effect. I thought I checked the output from tail before putting the back-ticks.
What did I do wrong?