Jump to content

Question

Posted

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

Share this post


Link to post
Share on other sites

6 answers to this question

  • 0

Posted

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

Share this post


Link to post
Share on other sites
  • 0

Posted

Thank you, it works great :)

Any chance there is a shorter way to do it?

Share this post


Link to post
Share on other sites
  • 0

Posted

not that I can think of.

 

Is that not short enough by itself?

Share this post


Link to post
Share on other sites
  • 0

Posted

It is, just a bit harder to remember :D 

 

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

Share this post


Link to post
Share on other sites
  • 0

Posted

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
}

Share this post


Link to post
Share on other sites
  • 0

Posted

 

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)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.