Jump to content



Photo

Linux redirect output to file question


  • Please log in to reply
6 replies to this topic

#1 +V-Tech

V-Tech

    Neowinian Senior

  • Joined: 06-January 05
  • Location: 127.0.0.1
  • OS: Windows 7 Enterprise
  • Phone: Nexus 5

Posted 26 June 2013 - 05:51

Hello guys...

 

So let's say i do

cat ifcfg-eth? > test.txt

Now i have 3 different eth and i want that when the info goes into the file it will place space or some kind of a break between each eth info.

 

Can i do this?

 

 

Thanks




#2 +Duble Kay

Duble Kay

    They flutter behind you your possible pasts

  • Joined: 24-October 03
  • Location: New Zealand
  • OS: Windows 8.1
  • Phone: Galaxy S5

Posted 26 June 2013 - 06:00

for i in ifcfg-eth?;do cat $i >> test.txt ; echo >> test.txt; done

 

that should place a balnk line between each ifcfg entry in the test.txt file



#3 OP +V-Tech

V-Tech

    Neowinian Senior

  • Joined: 06-January 05
  • Location: 127.0.0.1
  • OS: Windows 7 Enterprise
  • Phone: Nexus 5

Posted 26 June 2013 - 06:09

Thank you, it works great :)

Any chance there is a shorter way to do it?



#4 +Duble Kay

Duble Kay

    They flutter behind you your possible pasts

  • Joined: 24-October 03
  • Location: New Zealand
  • OS: Windows 8.1
  • Phone: Galaxy S5

Posted 26 June 2013 - 06:23

not that I can think of.

 

Is that not short enough by itself?



#5 OP +V-Tech

V-Tech

    Neowinian Senior

  • Joined: 06-January 05
  • Location: 127.0.0.1
  • OS: Windows 7 Enterprise
  • Phone: Nexus 5

Posted 26 June 2013 - 06:55

It is, just a bit harder to remember :D 

 

That's o.k, thanks a lot for the help.....  (Y)



#6 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 26 June 2013 - 19:19

If this is something you do frequently on your machine, have you considered aliasing it? I have many aliases that allow me to do things faster, and I would absolutely create an alias for that command if I used it frequently.

 

Add something like the following to your ~/.bash_aliases or ~/.bashrc:

function catifcfg
{
    if [ -n "$1" ]; then
        outfile="$1"
    else
        outfile='test.txt'
    fi
    
    for infile in ifcfg-eth?; do
        cat $infile >> $outfile
        echo >> $outfile
    done
}


#7 OP +V-Tech

V-Tech

    Neowinian Senior

  • Joined: 06-January 05
  • Location: 127.0.0.1
  • OS: Windows 7 Enterprise
  • Phone: Nexus 5

Posted 27 June 2013 - 18:33

 

If this is something you do frequently on your machine, have you considered aliasing it? I have many aliases that allow me to do things faster, and I would absolutely create an alias for that command if I used it frequently.

 

Add something like the following to your ~/.bash_aliases or ~/.bashrc:

function catifcfg
{
    if [ -n "$1" ]; then
        outfile="$1"
    else
        outfile='test.txt'
    fi
    
    for infile in ifcfg-eth?; do
        cat $infile >> $outfile
        echo >> $outfile
    done
}

Thank you, it's a good idea to do it this way....  (Y)