Author Topic: Adding a team identifier  (Read 22065 times)

Offline G Man

  • Newcomer
  • *
  • Posts: 20
    • View Profile
Adding a team identifier
« on: February 09, 2015, 06:06:41 AM »
Is it possible to add a team identifier, (in this case) a "c" to an multiple entries?    In the image, (attached below) I have been adding the "c" individually.  It would be great if it is possible with a command where it will paste it in every row.    If you are wondering, the copy is where I get my rosters.  I copy it from a listing online, paste in notepad++. 



[attachment deleted by admin]

Offline Hayo Baan

  • Uber Member
  • ******
  • Posts: 2552
  • Professional Photographer & Software Developer
    • View Profile
    • Hayo Baan - Photography
Re: Adding a team identifier
« Reply #1 on: February 09, 2015, 06:43:19 AM »
I would do this on the command-line. If you have e.g., Perl installed something like this would add a c in front of every line:

perl -pi -E "s/^/c/" file
(the -i option does an in-place replacement, leave off the i to test your command.)
Hayo Baan - Photography
Web: www.hayobaan.nl

Offline G Man

  • Newcomer
  • *
  • Posts: 20
    • View Profile
Re: Adding a team identifier
« Reply #2 on: February 09, 2015, 06:45:08 AM »
Thank you.   But I was hoping for a solution a mere photographer could understand!   ???

Offline Hayo Baan

  • Uber Member
  • ******
  • Posts: 2552
  • Professional Photographer & Software Developer
    • View Profile
    • Hayo Baan - Photography
Re: Adding a team identifier
« Reply #3 on: February 09, 2015, 07:36:34 AM »
I understand ;)

Perhaps notepad++ allows you to record keyboard macros, this could then be a solution too.
Hayo Baan - Photography
Web: www.hayobaan.nl

Offline Odd Skjaeveland

  • Full Member
  • ***
  • Posts: 188
    • View Profile
Re: Adding a team identifier
« Reply #4 on: February 09, 2015, 11:11:35 PM »
But I was hoping for a solution a mere photographer could understand!

Your Notepad++ should support find/replace using regular expressions.

Open the file and then try

a) Menu-line->Search->Find...  (or press keys Ctrl+F)
b) Select the Replace pane in the pop up Find dialog
c) Set Search Mode to Regular Expression
d) Type a single cirumflex (^) in the Find What field
e) Type the c in the Replace With field
f) Click the Replace All button

The circumflex character ^ means "at line start" in regular expressions
If you want to remove the leading c character, set the Find What to ^c that literally spells line start and then c. Clear the Replace With field and do Replace All

--
Odd S.
--
Odd S.

Offline G Man

  • Newcomer
  • *
  • Posts: 20
    • View Profile
Re: Adding a team identifier
« Reply #5 on: February 10, 2015, 06:18:28 AM »
The you Odd one!  Excellent information!

Offline G Man

  • Newcomer
  • *
  • Posts: 20
    • View Profile
Re: Adding a team identifier
« Reply #6 on: February 16, 2015, 07:19:50 PM »
ok, the identifier trick is working well!

Now, is it also possible to add a team name to the listing immediately before the player names? 

Offline Odd Skjaeveland

  • Full Member
  • ***
  • Posts: 188
    • View Profile
Re: Adding a team identifier
« Reply #7 on: February 16, 2015, 11:31:03 PM »
Now, is it also possible to add a team name to the listing immediately before the player names?

What exactly is a player name in your sample? If player name is defined as everything in the second field in your tab-separated records, it will be very simple.
Inserting a new second field after the first (team identifier) is also very simple. Inserting a team name in front of a specific entity in existing strings  that have a varying mix of entities where one entity is the player name, will require more effort. At some point I would definitely shoot with Perl, the tool Hayo Baan pointed you to in the first place.

Your sample shows the second field having text like "Parkway Central Froward Tyler Alms" and "Adam Boonshaft". If the real player names are Tyler Alms and Adam Boonshaft, then adding "Team A" to the beginning of the second field would be ok for "Team A Adam Boonshaft". However; "Team A Parkway Central Froward Tyler Alms" may not be the answer to your question.

Can you clearify/demonstrate what you actually want to do using the two first entries in your sample?

--
Odd S.


--
Odd S.

Offline G Man

  • Newcomer
  • *
  • Posts: 20
    • View Profile
Re: Adding a team identifier
« Reply #8 on: February 17, 2015, 06:57:02 AM »
Hello Odd......attached is a sample of how the info I start with.  I copy from the website and paste into a Notepad ++ document.
With your help, (thanks again), I am now able to insert  single character (team identifier) before the numeral. 

So, what I'd now like to do is add a team name such as:  " CBC's"  immediately after the first tab before the players name.....

I"m not familiar with using the team A function....

Thanks.



[attachment deleted by admin]

Offline Odd Skjaeveland

  • Full Member
  • ***
  • Posts: 188
    • View Profile
Re: Adding a team identifier
« Reply #9 on: February 17, 2015, 08:32:33 AM »
I"m not familiar with using the team A function....

Hah, me neither. My "Team A" was a failed attempt to demonstrate a team name of some sort to be added in front of a player name. Sorry about causing  confusion.

If your starting point is records having TAB-separated fields as shown, there will be several ways to insert a team name just about anywhere.

You have already used the regular expression special character circumflex (^) to indicate "start of line" (or rather start of text). A regular expression (regexp) recognizes quite a few special characters, like the dollar sign ($) meaning the "end of line" (or rather end of text) in case you run into that.

The first thing you probably need to know about at this point is the \t (backslash t) which means TAB.

There are a few more things to know, as well:

\d is a digit 0-9
\d+ is one or more digits

\w is word character, meaning any letter A-Z or a-z or any digit 0-9. A character we use when constructing a word, basically
\w+ means one or more word characters, \w+ essentially means one non-empty word.

Thus, in regexp speak the relevant beginning of your input lines are recognized as: ^\d+\t\w+
It spells: at start of line, one or more digits, then a TAB and then at least one word caracter. It fits 34TABNigel on your first input line. If you want it to fit Nigel Bracey you need ^\d+\t\w+\s+\w+ That adds at least one space and one more word to the mix.

Don't worry, you can probably get away with just ^\d+\t (start of line, then at least one digit and then TAB) to put a team name in front of the name, but I think you should learn just one more concept. Grouping by parenthesis. If you rewrite  ^\d+\t to ^(\d+)\t you make the digits into a group for later reference. No worries, you already know how to use alternative code replacements in PM (#1, #2 etc, and your regexp group of digits is similar).

Now try
Find what:  ^(\d+)\t
Replace with c\1\tTEAM-NAME-HERE\t

The \1 references the first group in the Find what statement, the digit collection that is. You put them after the leading c character. If you expanded the find to ^(\d+)\t(\w+), you could reference the second group found (a player's first name like Nigel, that is) using \2. If you followed this far, you should now be able to put the team name between the player's first and last name...

Note that I added a \t to insert a TAB after the team name (I tried something more obvious than "Team A" here  :). I suggest keeping entities in separate fields (or separate columns if you like) rather than combining several entities, like team name and person name, in one field. If you would rather want to have the team name in the name field (column) separated from the name string by a space, then put a space rather than a \t at the end of the team name.

I feel this discussion forum  may be the wrong place to teach regular expressions, I may unintentionally have annoyed a lot of PM users already. Jeffrey Friedl once wrote the excellent book "Mastering Regular Expressions" published by O'Reilly. I think it can be downloaded as a PDF by now, possibly at almost no cost. Check it out.

--
Odd S.


PS. I managed to misspell Jeffrey Friedl's name, now fixed.
« Last Edit: February 17, 2015, 09:59:23 AM by Odd Skjaeveland »
--
Odd S.

Offline G Man

  • Newcomer
  • *
  • Posts: 20
    • View Profile
Re: Adding a team identifier
« Reply #10 on: February 27, 2015, 04:41:23 AM »
Thanks Odd.  I shall give it a try!