Just trying to cut any characters after the 7th on each line of a text.I initially tried this:sed 's/(.{7}).*/\1/' TestText.txt But got this response:sed: 1: s/(.{7}).*/\1/: \1 not defined in the REThen tried this:$ sed 's/./&#/7' TestText.txt Ballbou#nceLatllma#tattjsdfdsfase,#d,adfadfj#jenasdfjov#moeo$ sed -e 's/#.*//' TestText.txt BallbounceLatllmatattjsdfdsfase,d,adfadfjjenasdfjovmoeoBut all it did was remove the #. I just want to remove any character after the 7th character.
Using SED to cut after 7th character of each line
text processing;sed
Use sed with -r:sed -r 's/(.{7}).*/\1/' fileOr escape the brackets:sed 's/\(.\{7\}\).*/\1/' fileAlternatively, you can also use grep (-E activates extended regular expressions, -o prints only the matching pattern):grep -oE '^.{7}' fileWith awk:awk '{print substr($0,1,7)}' fileAnd of course cut is just made for this kind of job:cut -c1-7 file