Find the answer to your Linux question:
Results 1 to 4 of 4
Hi All, Could you please help me out here! Issues: I have the file name like A4LNEU__20061123. I would like like the split the name of the file to 2 ...
  1. #1
    Just Joined!
    Join Date
    Feb 2007
    Posts
    18

    Split the name to 2 parts

    Hi All,

    Could you please help me out here!

    Issues:
    I have the file name like A4LNEU__20061123. I would like like the split the name of the file to 2 parts. Each part should have only 4 characters.
    like:
    Part1:A4LN
    Part2:EU__

    I need to redirect the out put to one more file.

    Please help me out to resolve this issue.

    Many Thanks,
    Vishnu.

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    eg in bash interaction
    Code:
    # var=A4LNEU__20061123
    # var1=$(expr "$var" : '\(.*__\)')
    # echo $var1
    A4LNEU__
    # lenvar1=${#var1}
    # lenvar1half=$((${#var1}/2)) #depending on whether you know the length 
    # first=${var1:0:$lenvar1half}
    # second=${var1:$lenvar1half}
    # echo $first $second
    A4LN EU__

  3. #3
    Just Joined!
    Join Date
    Feb 2007
    Posts
    18
    Thanks a lot for your help !! Its working fine


    Kind Regards,
    Vishnu.

  4. #4
    Just Joined!
    Join Date
    Jun 2007
    Posts
    4

    Can also do this in one line:

    echo A4LNEU__20061123 | sed -r 's/^(....)(....).*$/\1\n\2/'

    You can then redirect result into a file using '>' redirection.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...