I would like make a sed
In fact, I would replace it in my input file, position 54 by Z, where in position 54 is blank. So there is a requirement to add.
could someone help me please
Printable View
I would like make a sed
In fact, I would replace it in my input file, position 54 by Z, where in position 54 is blank. So there is a requirement to add.
could someone help me please
Hi.
Welcome to the forum.
Here is one solution for specific position character replacement. The surrounding lines are to display the computing environment:
producing:Code:#!/usr/bin/env bash
# @(#) s1 Demonstrate character replacement by position, sed.
# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
edges() { local _f _n _l;: ${1?"edges: need file"}; _f=$1;_l=$(wc -l $_f);
head -${_n:=3} $_f ; pe "--- ( $_l: lines total )" ; tail -$_n $_f ; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C sed
FILE=${1-data1}
pl " Input data file $FILE:"
cat $FILE
pl " Results:"
sed 's/^\(.\{53\}\) /\1Z/' $FILE
exit 0
See man sed for details.Code:% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0.8 (lenny)
bash GNU bash 3.2.39
sed GNU sed version 4.1.5
-----
Input data file data1:
xxxxxxxxx1xxxxxxxxx2xxxxxxxxx3xxxxxxxxx4xxxxxxxxx5xxxxxxxxx6xxxxxxxxx7xxxxxxxx
12345678901234567890123456789012345678901234567890123 567890123456789012345678
xxxxxxxxx1xxxxxxxxx2xxxxxxxxx3xxxxxxxxx4xxxxxxxxx5xxxxxxxxx6xxxxxxxxx7xxxxxxxx
123456789012345678901234567890123456789012345678901234567890123456789012345678
-----
Results:
xxxxxxxxx1xxxxxxxxx2xxxxxxxxx3xxxxxxxxx4xxxxxxxxx5xxxxxxxxx6xxxxxxxxx7xxxxxxxx
12345678901234567890123456789012345678901234567890123Z567890123456789012345678
xxxxxxxxx1xxxxxxxxx2xxxxxxxxx3xxxxxxxxx4xxxxxxxxx5xxxxxxxxx6xxxxxxxxx7xxxxxxxx
123456789012345678901234567890123456789012345678901234567890123456789012345678
Note:
Best wishes ... cheers, drlQuote:
Advice for forum posts, general:
To obtain the best answers quickly for processing datasets --
extracting, transforming, filtering, you should:
1. Post representative samples of your data (i.e. data that
should "succeed" and data that should "fail")
2. Post what you expect the results to be, in addition to
describing them. Be clear about how the results are to be
obtained, e.g. "add field 2 in file1 to field 3 from file2"
3. Post what you have attempted to do so far.
4. Place the data and expected output within CODE tags, so that
they are more easily readable.
Special cases, exceptions, etc., are very important to include
in the samples.