Adding a character string to every line in a file, incrementing that character string added by 1 each file

colin

I have some set of files with character strings in lines such that there is a folder containing

file1
file2
file3

and within those files there a variable length lists of strings of characters such that file 1 may read

file1.itemA
file1.itemB
file1.itemC

While file 2 may only contain

file2.itemA
file2.itemB

I want to add a file specific code to every line within each file such that

code1.file1.itemA
code1.file1.itemB
code1.file1.itemC

And

code2.file2.itemA
code2.file2.itemB

How can I do this within unix? I am using the OSX terminal to execute commands.

bishop

I'm not near a terminal to test, but, how about:

cd /path/to/your/files
word='code'
base=1
for file in *; do sed -i -e "s/^/$word$base/" "${file}"; base=$(( $base + 1 )); done

The $word variable is the constant you want. The $base variable holds the count that is incremented on each file, initially set to 1.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Adding a character string to every line in a file, incrementing that character string added by 1 each file

From Dev

how to extract particular string with special character from each line of a file

From Dev

how to extract particular string with special character from each line of a file

From Dev

Java incrementing every character in a string by a large amount?

From Dev

Finding the last character of a file and adding a string after that?

From Dev

Parsing a file line by line for key character in string and copying line

From Dev

Remove string after character in every line break

From Dev

Insert character into String in Batch File

From Dev

EOF file character in a string/buffer

From Dev

add a character to each line in a text file php

From Dev

Reading only first character of each line in file

From Dev

add a character to each line in a text file php

From Dev

split string at every character

From Dev

Adding a character in the middle of a string

From Dev

Adding character to a string in sql

From Dev

Incrementing an integer by +1 and adding to string

From Dev

Add each character from each line of a text file, to a list in Python

From Dev

powershell delete everything after character for every line in a file

From Dev

Read in every line that starts with a certain character from a file

From Dev

Copy only the text until special character on every line into another file

From Dev

Shiny error: 'file' must be a character string or connection

From Dev

Scanning a string from a file ignoring the last character

From Dev

Scanning a string from a file ignoring the last character

From Dev

How to find character locations of a string in a file?

From Dev

Last index of a character in an input string in a batch file

From Dev

adding a variable length padding to each element in a string/character vector

From Dev

adding a character to a specific position of the file for each record in Unix

From Dev

XSLT split string on every character

From Dev

Java - String splits by every character

Related Related

  1. 1

    Adding a character string to every line in a file, incrementing that character string added by 1 each file

  2. 2

    how to extract particular string with special character from each line of a file

  3. 3

    how to extract particular string with special character from each line of a file

  4. 4

    Java incrementing every character in a string by a large amount?

  5. 5

    Finding the last character of a file and adding a string after that?

  6. 6

    Parsing a file line by line for key character in string and copying line

  7. 7

    Remove string after character in every line break

  8. 8

    Insert character into String in Batch File

  9. 9

    EOF file character in a string/buffer

  10. 10

    add a character to each line in a text file php

  11. 11

    Reading only first character of each line in file

  12. 12

    add a character to each line in a text file php

  13. 13

    split string at every character

  14. 14

    Adding a character in the middle of a string

  15. 15

    Adding character to a string in sql

  16. 16

    Incrementing an integer by +1 and adding to string

  17. 17

    Add each character from each line of a text file, to a list in Python

  18. 18

    powershell delete everything after character for every line in a file

  19. 19

    Read in every line that starts with a certain character from a file

  20. 20

    Copy only the text until special character on every line into another file

  21. 21

    Shiny error: 'file' must be a character string or connection

  22. 22

    Scanning a string from a file ignoring the last character

  23. 23

    Scanning a string from a file ignoring the last character

  24. 24

    How to find character locations of a string in a file?

  25. 25

    Last index of a character in an input string in a batch file

  26. 26

    adding a variable length padding to each element in a string/character vector

  27. 27

    adding a character to a specific position of the file for each record in Unix

  28. 28

    XSLT split string on every character

  29. 29

    Java - String splits by every character

HotTag

Archive